00001
00002
00003
00004
00005
00006
00007
00008
00014 #ifndef __GEARMAN_CONNECTION_H__
00015 #define __GEARMAN_CONNECTION_H__
00016
00017 #ifdef __cplusplus
00018 extern "C" {
00019 #endif
00020
00036 struct gearman_connection_st
00037 {
00038 struct {
00039 bool allocated LIBGEARMAN_BITFIELD;
00040 bool ready LIBGEARMAN_BITFIELD;
00041 bool packet_in_use LIBGEARMAN_BITFIELD;
00042 bool external_fd LIBGEARMAN_BITFIELD;
00043 bool ignore_lost_connection LIBGEARMAN_BITFIELD;
00044 bool close_after_flush LIBGEARMAN_BITFIELD;
00045 } options;
00046 enum {
00047 GEARMAN_CON_UNIVERSAL_ADDRINFO,
00048 GEARMAN_CON_UNIVERSAL_CONNECT,
00049 GEARMAN_CON_UNIVERSAL_CONNECTING,
00050 GEARMAN_CON_UNIVERSAL_CONNECTED
00051 } state;
00052 enum {
00053 GEARMAN_CON_SEND_STATE_NONE,
00054 GEARMAN_CON_SEND_UNIVERSAL_PRE_FLUSH,
00055 GEARMAN_CON_SEND_UNIVERSAL_FORCE_FLUSH,
00056 GEARMAN_CON_SEND_UNIVERSAL_FLUSH,
00057 GEARMAN_CON_SEND_UNIVERSAL_FLUSH_DATA
00058 } send_state;
00059 enum {
00060 GEARMAN_CON_RECV_UNIVERSAL_NONE,
00061 GEARMAN_CON_RECV_UNIVERSAL_READ,
00062 GEARMAN_CON_RECV_STATE_READ_DATA
00063 } recv_state;
00064 in_port_t port;
00065 short events;
00066 short revents;
00067 int fd;
00068 uint32_t created_id;
00069 uint32_t created_id_next;
00070 size_t send_buffer_size;
00071 size_t send_data_size;
00072 size_t send_data_offset;
00073 size_t recv_buffer_size;
00074 size_t recv_data_size;
00075 size_t recv_data_offset;
00076 gearman_universal_st *universal;
00077 gearman_connection_st *next;
00078 gearman_connection_st *prev;
00079 void *context;
00080 struct addrinfo *addrinfo;
00081 struct addrinfo *addrinfo_next;
00082 char *send_buffer_ptr;
00083 gearman_packet_st *recv_packet;
00084 char *recv_buffer_ptr;
00085 void *protocol_context;
00086 gearman_connection_protocol_context_free_fn *protocol_context_free_fn;
00087 gearman_packet_pack_fn *packet_pack_fn;
00088 gearman_packet_unpack_fn *packet_unpack_fn;
00089 gearman_packet_st packet;
00090 char host[NI_MAXHOST];
00091 char send_buffer[GEARMAN_SEND_BUFFER_SIZE];
00092 char recv_buffer[GEARMAN_RECV_BUFFER_SIZE];
00093 };
00094
00095 #ifdef GEARMAN_CORE
00096
00108 GEARMAN_INTERNAL_API
00109 gearman_connection_st *gearman_connection_create(gearman_universal_st *gearman,
00110 gearman_connection_st *connection,
00111 gearman_connection_options_t *options);
00112
00124 GEARMAN_INTERNAL_API
00125 gearman_connection_st *gearman_connection_create_args(gearman_universal_st *gearman,
00126 gearman_connection_st *connection,
00127 const char *host, in_port_t port);
00128
00139 GEARMAN_INTERNAL_API
00140 gearman_connection_st *gearman_connection_clone(gearman_universal_st *gearman, gearman_connection_st *src,
00141 const gearman_connection_st *from);
00142
00149 GEARMAN_INTERNAL_API
00150 void gearman_connection_free(gearman_connection_st *connection);
00151
00152
00153 GEARMAN_INTERNAL_API
00154 gearman_return_t gearman_connection_set_option(gearman_connection_st *connection,
00155 gearman_connection_options_t options,
00156 bool value);
00157
00158
00162 GEARMAN_INTERNAL_API
00163 void gearman_connection_set_host(gearman_connection_st *connection,
00164 const char *host,
00165 in_port_t port);
00166
00170 GEARMAN_INTERNAL_API
00171 gearman_return_t gearman_connection_set_fd(gearman_connection_st *connection, int fd);
00172
00176 GEARMAN_INTERNAL_API
00177 void *gearman_connection_context(const gearman_connection_st *connection);
00178
00182 GEARMAN_INTERNAL_API
00183 void gearman_connection_set_context(gearman_connection_st *connection, void *context);
00184
00188 GEARMAN_INTERNAL_API
00189 gearman_return_t gearman_connection_connect(gearman_connection_st *connection);
00190
00194 GEARMAN_INTERNAL_API
00195 void gearman_connection_close(gearman_connection_st *connection);
00196
00200 GEARMAN_INTERNAL_API
00201 gearman_return_t gearman_connection_send(gearman_connection_st *connection,
00202 const gearman_packet_st *packet, bool flush);
00203
00207 GEARMAN_INTERNAL_API
00208 size_t gearman_connection_send_data(gearman_connection_st *connection, const void *data,
00209 size_t data_size, gearman_return_t *ret_ptr);
00210
00214 GEARMAN_INTERNAL_API
00215 gearman_return_t gearman_connection_flush(gearman_connection_st *connection);
00216
00220 GEARMAN_INTERNAL_API
00221 gearman_packet_st *gearman_connection_recv(gearman_connection_st *connection,
00222 gearman_packet_st *packet,
00223 gearman_return_t *ret_ptr, bool recv_data);
00224
00228 GEARMAN_INTERNAL_API
00229 size_t gearman_connection_recv_data(gearman_connection_st *connection, void *data, size_t data_size,
00230 gearman_return_t *ret_ptr);
00231
00235 GEARMAN_INTERNAL_API
00236 size_t gearman_connection_read(gearman_connection_st *connection, void *data, size_t data_size,
00237 gearman_return_t *ret_ptr);
00238
00242 GEARMAN_INTERNAL_API
00243 gearman_return_t gearman_connection_set_events(gearman_connection_st *connection, short events);
00244
00249 GEARMAN_INTERNAL_API
00250 gearman_return_t gearman_connection_set_revents(gearman_connection_st *connection, short revents);
00251
00255 GEARMAN_INTERNAL_API
00256 void *gearman_connection_protocol_context(const gearman_connection_st *connection);
00257
00261 GEARMAN_INTERNAL_API
00262 void gearman_connection_set_protocol_context(gearman_connection_st *connection, void *context);
00263
00267 GEARMAN_INTERNAL_API
00268 void gearman_connection_set_protocol_context_free_fn(gearman_connection_st *connection,
00269 gearman_connection_protocol_context_free_fn *function);
00270
00274 GEARMAN_INTERNAL_API
00275 void gearman_connection_set_packet_pack_fn(gearman_connection_st *connection,
00276 gearman_packet_pack_fn *function);
00277
00281 GEARMAN_INTERNAL_API
00282 void gearman_connection_set_packet_unpack_fn(gearman_connection_st *connection,
00283 gearman_packet_unpack_fn *function);
00284
00287 #endif
00288
00289 #ifdef __cplusplus
00290 }
00291 #endif
00292
00293 #endif