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_CONNECTION_H 00025 #define SCALESTACK_DATABASEPROXY_CONNECTION_H 00026 00027 #include <scalestack/network/stream.h> 00028 00029 namespace scalestack 00030 { 00031 namespace database_proxy 00032 { 00033 00034 class client; 00035 class service; 00036 00037 class connection: public network::stream 00038 { 00039 public: 00040 00041 connection(service& creator); 00042 00046 size_t read(uint8_t* buffer, size_t size); 00047 00051 void continue_write(void); 00052 00056 void flush_write(void); 00057 00061 void error(void); 00062 00066 void run(void); 00067 00071 void yield(void); 00072 00073 private: 00074 00078 connection(const connection&); 00079 00083 connection& operator=(const connection&); 00084 00089 size_t _client_write(void); 00090 00091 enum 00092 { 00093 CLIENT_HANDSHAKE_PACKET, 00094 CLIENT_HANDSHAKE_FLUSH, 00095 COMMAND_PACKET, 00096 COMMAND_FLUSH 00097 } _state; 00098 bool _need_handshake; 00099 bool _need_yield; 00100 bool _in_transaction; 00101 bool _shutdown; 00102 size_t _size; 00103 size_t _packet_size; 00104 uint8_t* _buffer; 00105 client* _client; 00106 }; 00107 00108 } /* namespace database_proxy */ 00109 } /* namespace scalestack */ 00110 00111 #endif /* SCALESTACK_DATABASEPROXY_CONNECTION_H */
1.6.3