Merge lp:~brianaker/gearmand/remove-function into lp:gearmand

Proposed by Brian Aker
Status: Merged
Merged at revision: 812
Proposed branch: lp:~brianaker/gearmand/remove-function
Merge into: lp:gearmand
Diff against target: 427 lines (+130/-61)
13 files modified
libgearman-server/constants.h (+1/-0)
libgearman-server/gearmand.cc (+5/-3)
libgearman-server/gearmand.h (+2/-1)
libgearman-server/gearmand_con.cc (+27/-10)
libgearman-server/gearmand_con.h (+3/-3)
libgearman-server/gearmand_thread.cc (+1/-1)
libgearman-server/io.cc (+1/-0)
libgearman-server/plugins/protocol/gear/protocol.cc (+6/-1)
libgearman-server/plugins/protocol/http/protocol.cc (+6/-1)
libgearman-server/struct/gearmand_con.h (+12/-1)
libgearman-server/struct/io.h (+2/-0)
libgearman-server/struct/port.h (+27/-2)
libgearman/connection.cc (+37/-38)
To merge this branch: bzr merge lp:~brianaker/gearmand/remove-function
Reviewer Review Type Date Requested Status
Tangent Trunk Pending
Review via email: mp+173339@code.launchpad.net
To post a comment you must log in.

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
1=== modified file 'libgearman-server/constants.h'
2--- libgearman-server/constants.h 2013-05-07 11:07:18 +0000
3+++ libgearman-server/constants.h 2013-07-07 00:24:31 +0000
4@@ -137,6 +137,7 @@
5 void *add_context);
6
7 typedef gearmand_error_t (gearmand_connection_add_fn)(gearman_server_con_st *con);
8+typedef gearmand_error_t (gearmand_connection_remove_fn)(gearman_server_con_st *con);
9
10 typedef void (gearman_log_server_fn)(const char *line, gearmand_verbose_t verbose,
11 struct gearmand_thread_st *context);
12
13=== modified file 'libgearman-server/gearmand.cc'
14--- libgearman-server/gearmand.cc 2013-07-06 10:56:43 +0000
15+++ libgearman-server/gearmand.cc 2013-07-07 00:24:31 +0000
16@@ -316,13 +316,15 @@
17 }
18
19 gearmand_error_t gearmand_port_add(gearmand_st *gearmand, const char *port,
20- gearmand_connection_add_fn *function)
21+ gearmand_connection_add_fn *function,
22+ gearmand_connection_remove_fn* remove_)
23 {
24 assert(gearmand);
25 gearmand->_port_list.resize(gearmand->_port_list.size() +1);
26
27 strncpy(gearmand->_port_list.back().port, port, NI_MAXSERV);
28- gearmand->_port_list.back().add_fn= function;
29+ gearmand->_port_list.back().add_fn(function);
30+ gearmand->_port_list.back().remove_fn(remove_);
31
32 return GEARMAND_SUCCESS;
33 }
34@@ -885,7 +887,7 @@
35
36 gearmand_log_info(GEARMAN_DEFAULT_LOG_PARAM, "Accepted connection from %s:%s", host, port_str);
37
38- gearmand_error_t ret= gearmand_con_create(Gearmand(), fd, host, port_str, port->add_fn);
39+ gearmand_error_t ret= gearmand_con_create(Gearmand(), fd, host, port_str, port);
40 if (ret == GEARMAND_MEMORY_ALLOCATION_FAILURE)
41 {
42 gearmand_sockfd_close(fd);
43
44=== modified file 'libgearman-server/gearmand.h'
45--- libgearman-server/gearmand.h 2013-03-09 22:24:08 +0000
46+++ libgearman-server/gearmand.h 2013-07-07 00:24:31 +0000
47@@ -139,7 +139,8 @@
48 GEARMAN_API
49 gearmand_error_t gearmand_port_add(gearmand_st *gearmand,
50 const char *port,
51- gearmand_connection_add_fn *function);
52+ gearmand_connection_add_fn*,
53+ gearmand_connection_remove_fn*);
54
55 /**
56 * Run the server instance.
57
58=== modified file 'libgearman-server/gearmand_con.cc'
59--- libgearman-server/gearmand_con.cc 2013-07-06 09:37:11 +0000
60+++ libgearman-server/gearmand_con.cc 2013-07-07 00:24:31 +0000
61@@ -53,6 +53,11 @@
62 * Private declarations
63 */
64
65+void gearmand_con_st::close_socket()
66+{
67+ gearmand_sockfd_close(fd);
68+}
69+
70 /**
71 * @addtogroup gearmand_con_private Private Gearmand Connection Functions
72 * @ingroup gearmand_con
73@@ -70,19 +75,18 @@
74
75 if (dcon->server_con == NULL)
76 {
77- gearmand_sockfd_close(dcon->fd);
78-
79+ dcon->close_socket();
80 return ret;
81 }
82
83- if (dcon->add_fn)
84+ if (dcon->port_st())
85 {
86- ret= (*dcon->add_fn)(dcon->server_con);
87+ ret= dcon->add_fn(dcon->server_con);
88 if (gearmand_failed(ret))
89 {
90 gearman_server_con_free(dcon->server_con);
91
92- gearmand_sockfd_close(dcon->fd);
93+ dcon->close_socket();
94
95 return ret;
96 }
97@@ -93,6 +97,20 @@
98 return GEARMAND_SUCCESS;
99 }
100
101+gearmand_error_t gearmand_con_st::add_fn(gearman_server_con_st* con_st_)
102+{
103+ assert(_port_st);
104+ assert(con_st_);
105+ return _port_st->add_fn(con_st_);
106+}
107+
108+gearmand_error_t gearmand_con_st::remove_fn(gearman_server_con_st* con_st_)
109+{
110+ assert(_port_st);
111+ assert(con_st_);
112+ return _port_st->remove_fn(con_st_);
113+}
114+
115 void _con_ready(int, short events, void *arg)
116 {
117 gearmand_con_st *dcon= (gearmand_con_st *)(arg);
118@@ -515,9 +533,9 @@
119 return server_job;
120 }
121
122-gearmand_error_t gearmand_con_create(gearmand_st *gearmand, int fd,
123+gearmand_error_t gearmand_con_create(gearmand_st *gearmand, int& fd,
124 const char *host, const char *port,
125- gearmand_connection_add_fn *add_fn)
126+ struct gearmand_port_st* port_st_)
127 {
128 gearmand_con_st *dcon;
129
130@@ -545,12 +563,11 @@
131 dcon->next= NULL;
132 dcon->prev= NULL;
133 dcon->server_con= NULL;
134- dcon->add_fn= NULL;
135 strncpy(dcon->host, host, NI_MAXHOST);
136 dcon->host[NI_MAXHOST -1]= 0;
137 strncpy(dcon->port, port, NI_MAXSERV);
138 dcon->port[NI_MAXSERV -1]= 0;
139- dcon->add_fn= add_fn;
140+ dcon->_port_st= port_st_;
141
142 /* If we are not threaded, just add the connection now. */
143 if (gearmand->threads == 0)
144@@ -660,7 +677,7 @@
145
146 GEARMAND_LIST__DEL(dcon->thread->dcon, dcon);
147
148- gearmand_sockfd_close(dcon->fd);
149+ dcon->close_socket();
150
151 if (Gearmand()->free_dcon_count < GEARMAND_MAX_FREE_SERVER_CON)
152 {
153
154=== modified file 'libgearman-server/gearmand_con.h'
155--- libgearman-server/gearmand_con.h 2013-03-21 07:40:50 +0000
156+++ libgearman-server/gearmand_con.h 2013-07-07 00:24:31 +0000
157@@ -74,9 +74,9 @@
158 * @return Pointer to an allocated gearmand structure.
159 */
160 GEARMAN_API
161-gearmand_error_t gearmand_con_create(gearmand_st *gearmand, int fd,
162- const char *host, const char *port,
163- gearmand_connection_add_fn *add_fn);
164+gearmand_error_t gearmand_con_create(gearmand_st *gearmand, int&,
165+ const char *host, const char*,
166+ struct gearmand_port_st*);
167
168 bool gearman_server_job_cancel(gearman_server_st& server,
169 const char *job_handle,
170
171=== modified file 'libgearman-server/gearmand_thread.cc'
172--- libgearman-server/gearmand_thread.cc 2013-07-06 10:56:43 +0000
173+++ libgearman-server/gearmand_thread.cc 2013-07-07 00:24:31 +0000
174@@ -339,7 +339,7 @@
175 {
176 gearmand_con_st* dcon= thread->dcon_add_list;
177 thread->dcon_add_list= dcon->next;
178- gearmand_sockfd_close(dcon->fd);
179+ dcon->close_socket();
180 delete dcon;
181 }
182
183
184=== modified file 'libgearman-server/io.cc'
185--- libgearman-server/io.cc 2013-07-06 11:00:30 +0000
186+++ libgearman-server/io.cc 2013-07-07 00:24:31 +0000
187@@ -74,6 +74,7 @@
188 if (connection->root and connection->root->_ssl)
189 {
190 CyaSSL_shutdown(connection->root->_ssl);
191+ CyaSSL_free(connection->root->_ssl);
192 connection->root->_ssl= NULL;
193 }
194 #endif
195
196=== modified file 'libgearman-server/plugins/protocol/gear/protocol.cc'
197--- libgearman-server/plugins/protocol/gear/protocol.cc 2013-07-06 20:11:54 +0000
198+++ libgearman-server/plugins/protocol/gear/protocol.cc 2013-07-07 00:24:31 +0000
199@@ -314,6 +314,11 @@
200
201 static Geartext gear_context;
202
203+static gearmand_error_t _gear_con_remove(gearman_server_con_st*)
204+{
205+ return GEARMAND_SUCCESS;
206+}
207+
208 static gearmand_error_t _gear_con_add(gearman_server_con_st *connection)
209 {
210 #if defined(HAVE_CYASSL) && HAVE_CYASSL
211@@ -436,7 +441,7 @@
212 }
213 #endif
214
215- rc= gearmand_port_add(gearmand, _port.c_str(), _gear_con_add);
216+ rc= gearmand_port_add(gearmand, _port.c_str(), _gear_con_add, _gear_con_remove);
217
218 return rc;
219 }
220
221=== modified file 'libgearman-server/plugins/protocol/http/protocol.cc'
222--- libgearman-server/plugins/protocol/http/protocol.cc 2013-05-12 01:03:50 +0000
223+++ libgearman-server/plugins/protocol/http/protocol.cc 2013-07-07 00:24:31 +0000
224@@ -633,6 +633,11 @@
225 std::vector<char> content;
226 };
227
228+static gearmand_error_t _http_con_remove(gearman_server_con_st*)
229+{
230+ return GEARMAND_SUCCESS;
231+}
232+
233 static gearmand_error_t _http_con_add(gearman_server_con_st *connection)
234 {
235 gearmand_info("HTTP connection made");
236@@ -666,7 +671,7 @@
237 gearmand_error_t HTTP::start(gearmand_st *gearmand)
238 {
239 gearmand_info("Initializing HTTP");
240- return gearmand_port_add(gearmand, _port.c_str(), _http_con_add);
241+ return gearmand_port_add(gearmand, _port.c_str(), _http_con_add, _http_con_remove);
242 }
243
244 } // namespace protocol
245
246=== modified file 'libgearman-server/struct/gearmand_con.h'
247--- libgearman-server/struct/gearmand_con.h 2011-12-08 17:53:07 +0000
248+++ libgearman-server/struct/gearmand_con.h 2013-07-07 00:24:31 +0000
249@@ -45,9 +45,20 @@
250 gearmand_con_st *next;
251 gearmand_con_st *prev;
252 gearman_server_con_st *server_con;
253- gearmand_connection_add_fn *add_fn;
254 struct event event;
255 char host[NI_MAXHOST];
256 char port[NI_MAXSERV];
257+ struct gearmand_port_st* _port_st;
258+
259+ struct gearmand_port_st* port_st()
260+ {
261+ return _port_st;
262+ }
263+
264+ gearmand_error_t add_fn(gearman_server_con_st*);
265+
266+ gearmand_error_t remove_fn(gearman_server_con_st*);
267+
268+ void close_socket();
269 };
270
271
272=== modified file 'libgearman-server/struct/io.h'
273--- libgearman-server/struct/io.h 2013-07-06 09:37:11 +0000
274+++ libgearman-server/struct/io.h 2013-07-07 00:24:31 +0000
275@@ -97,6 +97,8 @@
276
277 const char* host() const;
278 const char* port() const;
279+
280+ void close_socket();
281 };
282
283 namespace gearmand { namespace protocol {class Context; } }
284
285=== modified file 'libgearman-server/struct/port.h'
286--- libgearman-server/struct/port.h 2013-01-13 12:23:14 +0000
287+++ libgearman-server/struct/port.h 2013-07-07 00:24:31 +0000
288@@ -43,13 +43,18 @@
289 {
290 char port[NI_MAXSERV];
291 uint32_t listen_count;
292- gearmand_connection_add_fn *add_fn;
293+
294+private:
295+ gearmand_connection_add_fn *_add_fn;
296+ gearmand_connection_remove_fn *_remove_fn;
297+
298+public:
299 int *listen_fd;
300 struct event *listen_event;
301
302 gearmand_port_st() :
303 listen_count(0),
304- add_fn(NULL),
305+ _add_fn(NULL),
306 listen_fd(NULL),
307 listen_event(NULL)
308 {
309@@ -68,5 +73,25 @@
310 free(listen_event);
311 }
312 }
313+
314+ gearmand_error_t add_fn(gearman_server_con_st* con)
315+ {
316+ return (*_add_fn)(con);
317+ }
318+
319+ gearmand_error_t remove_fn(gearman_server_con_st* con)
320+ {
321+ return (*_remove_fn)(con);
322+ }
323+
324+ void add_fn(gearmand_connection_add_fn* add_fn_)
325+ {
326+ _add_fn= add_fn_;
327+ }
328+
329+ void remove_fn(gearmand_connection_remove_fn* remove_fn_)
330+ {
331+ _remove_fn= remove_fn_;
332+ }
333 };
334
335
336=== modified file 'libgearman/connection.cc'
337--- libgearman/connection.cc 2013-07-06 20:11:54 +0000
338+++ libgearman/connection.cc 2013-07-07 00:24:31 +0000
339@@ -294,51 +294,50 @@
340 if (_ssl)
341 {
342 #if defined(HAVE_CYASSL) && HAVE_CYASSL
343+ CyaSSL_shutdown(_ssl);
344 CyaSSL_free(_ssl);
345 _ssl= NULL;
346 #endif
347 }
348
349- if (fd == INVALID_SOCKET)
350- {
351- return;
352- }
353-
354- /* in case of death shutdown to avoid blocking at close_socket() */
355- if (shutdown(fd, SHUT_RDWR) == SOCKET_ERROR && get_socket_errno() != ENOTCONN)
356- { }
357- else
358- {
359- if (closesocket(fd) == SOCKET_ERROR)
360+ if (fd != INVALID_SOCKET)
361+ {
362+ /* in case of death shutdown to avoid blocking at close_socket() */
363+ if (shutdown(fd, SHUT_RDWR) == SOCKET_ERROR && get_socket_errno() != ENOTCONN)
364 { }
365+ else
366+ {
367+ if (closesocket(fd) == SOCKET_ERROR)
368+ { }
369+ }
370+
371+ state= GEARMAN_CON_UNIVERSAL_CONNECT;
372+ fd= INVALID_SOCKET;
373+ events= 0;
374+ revents= 0;
375+
376+ send_state= GEARMAN_CON_SEND_STATE_NONE;
377+ send_buffer_ptr= send_buffer;
378+ send_buffer_size= 0;
379+ send_data_size= 0;
380+ send_data_offset= 0;
381+
382+ recv_state= GEARMAN_CON_RECV_UNIVERSAL_NONE;
383+ free_recv_packet();
384+
385+ recv_buffer_ptr= recv_buffer;
386+ recv_buffer_size= 0;
387+
388+ options.server_options_sent= false;
389+
390+ // created_id_next is incremented for every outbound packet (except status).
391+ // created_id is incremented for every response packet received, and also when
392+ // no packets are received due to an error. There are lots of such error paths
393+ // and it seems simpler to just reset these both to zero when a connection is
394+ // 'closed'.
395+ created_id= 0;
396+ created_id_next= 0;
397 }
398-
399- state= GEARMAN_CON_UNIVERSAL_CONNECT;
400- fd= INVALID_SOCKET;
401- events= 0;
402- revents= 0;
403-
404- send_state= GEARMAN_CON_SEND_STATE_NONE;
405- send_buffer_ptr= send_buffer;
406- send_buffer_size= 0;
407- send_data_size= 0;
408- send_data_offset= 0;
409-
410- recv_state= GEARMAN_CON_RECV_UNIVERSAL_NONE;
411- free_recv_packet();
412-
413- recv_buffer_ptr= recv_buffer;
414- recv_buffer_size= 0;
415-
416- options.server_options_sent= false;
417-
418- // created_id_next is incremented for every outbound packet (except status).
419- // created_id is incremented for every response packet received, and also when
420- // no packets are received due to an error. There are lots of such error paths
421- // and it seems simpler to just reset these both to zero when a connection is
422- // 'closed'.
423- created_id= 0;
424- created_id_next= 0;
425 }
426
427 void gearman_connection_st::free_recv_packet()

Subscribers

People subscribed via source and target branches

to all changes: