00001 /* 00002 * Scale Stack 00003 * 00004 * Copyright 2010 Eric Day 00005 * 00006 * Licensed under the Apache License, Version 2.0 (the "License"); 00007 * you may not use this file except in compliance with the License. 00008 * You may obtain a copy of the License at 00009 * 00010 * http://www.apache.org/licenses/LICENSE-2.0 00011 * 00012 * Unless required by applicable law or agreed to in writing, software 00013 * distributed under the License is distributed on an "AS IS" BASIS, 00014 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 00015 * See the License for the specific language governing permissions and 00016 * limitations under the License. 00017 */ 00018 00024 #ifndef SCALESTACK_DATABASEPROXY_CLIENT_SERVICE_H 00025 #define SCALESTACK_DATABASEPROXY_CLIENT_SERVICE_H 00026 00027 #include <vector> 00028 00029 #include <scalestack/network/ip/tcp/connection_service.h> 00030 #include <scalestack/network/stream_service.h> 00031 00032 namespace scalestack 00033 { 00034 namespace database_proxy 00035 { 00036 00037 class client; 00038 class connection; 00039 00040 class client_service: public network::stream_service 00041 { 00042 public: 00043 00044 client_service(kernel::module& module); 00045 00046 ~client_service(); 00047 00051 network::stream* add_stream(void); 00052 00056 void remove_stream(network::stream* stream); 00057 00061 client* get_client(connection* connection, bool need_handshake); 00062 00066 void yield_client(client* client); 00067 00071 void remove_from_queue(connection* connection); 00072 00073 private: 00074 00078 client_service(const client_service&); 00079 00083 client_service& operator=(const client_service&); 00084 00085 size_t _max_clients; 00086 size_t _current_clients; 00087 pthread_mutex_t _queue_mutex; 00088 std::vector<connection*> _waiting_connections; 00089 std::vector<client*> _free_clients; 00090 network::ip::tcp::connection_service _connection_service; 00091 }; 00092 00093 } /* namespace database_proxy */ 00094 } /* namespace scalestack */ 00095 00096 #endif /* SCALESTACK_DATABASEPROXY_CLIENT_SERVICE_H */
1.6.3