1
/* vim:expandtab:shiftwidth=2:tabstop=2:smarttab:
3
* Gearmand client and server library.
5
* Copyright (C) 2011 Data Differential, http://datadifferential.com/
6
* Copyright (C) 2008 Brian Aker, Eric Day
9
* Redistribution and use in source and binary forms, with or without
10
* modification, are permitted provided that the following conditions are
13
* * Redistributions of source code must retain the above copyright
14
* notice, this list of conditions and the following disclaimer.
16
* * Redistributions in binary form must reproduce the above
17
* copyright notice, this list of conditions and the following disclaimer
18
* in the documentation and/or other materials provided with the
21
* * The names of its contributors may not be used to endorse or
22
* promote products derived from this software without specific prior
25
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
26
* "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
27
* LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
28
* A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
29
* OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
30
* SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
31
* LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
32
* DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
33
* THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
34
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
35
* OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
41
#include <libgearman-1.0/connection.h>
43
struct gearman_connection_st
49
enum gearman_con_universal_t state;
50
enum gearman_con_send_t send_state;
51
enum gearman_con_recv_t recv_state;
58
uint32_t created_id_next;
59
size_t send_buffer_size;
60
size_t send_data_size;
61
size_t send_data_offset;
62
size_t recv_buffer_size;
63
size_t recv_data_size;
64
size_t recv_data_offset;
65
gearman_universal_st &universal;
66
gearman_connection_st *next;
67
gearman_connection_st *prev;
69
struct addrinfo *addrinfo;
70
struct addrinfo *addrinfo_next;
71
char *send_buffer_ptr;
72
gearman_packet_st *recv_packet;
73
char *recv_buffer_ptr;
74
gearman_packet_st _packet;
75
char host[GEARMAN_NI_MAXHOST];
76
char send_buffer[GEARMAN_SEND_BUFFER_SIZE];
77
char recv_buffer[GEARMAN_RECV_BUFFER_SIZE];
79
void free_private_packet();
81
gearman_connection_st(gearman_universal_st &universal_arg,
82
gearman_connection_options_t *options);
84
~gearman_connection_st();
86
void set_host( const char *host, const in_port_t port);
88
gearman_return_t send_packet(const gearman_packet_st&, const bool flush_buffer);
89
size_t send_and_flush(const void *data, size_t data_size, gearman_return_t *ret_ptr);
91
gearman_return_t flush();
94
// Receive packet from a connection.
95
gearman_packet_st *receiving(gearman_packet_st&,
96
gearman_return_t& , const bool recv_data);
98
// Receive packet data from a connection.
99
size_t receiving(void *data, size_t data_size, gearman_return_t&);
101
// Set events to be watched for a connection.
102
void set_events(short events);
104
// Set events that are ready for a connection. This is used with the
105
// external event callbacks.
106
void set_revents(short revents);
108
void reset_addrinfo();
110
gearman_return_t lookup();
113
size_t recv_socket(void *data, size_t data_size, gearman_return_t&);
114
gearman_return_t connect_poll();
118
* Initialize a connection structure. Always check the return value even if
119
* passing in a pre-allocated structure. Some other initialization may have
124
gearman_connection_st *gearman_connection_create(gearman_universal_st &universal,
125
gearman_connection_options_t *options);
128
gearman_connection_st *gearman_connection_copy(gearman_universal_st& universal,
129
const gearman_connection_st& from);
132
* Create a connection structure with the given host and port.
134
* @param[in] gearman Structure previously initialized with gearman_create() or
136
* @param[in] connection Caller allocated structure, or NULL to allocate one.
137
* @param[in] host Host or IP address to connect to.
138
* @param[in] port Port to connect to.
139
* @return On success, a pointer to the (possibly allocated) structure. On
140
* failure this will be NULL.
143
gearman_connection_st *gearman_connection_create_args(gearman_universal_st &universal,
144
const char *host, in_port_t port);