equal
deleted
inserted
replaced
1 |
1 |
2 #include <stdlib.h> |
2 #include <stdlib.h> |
3 #include <assert.h> |
3 #include <assert.h> |
4 |
4 |
5 #include "server.h" |
5 #include "server.h" |
|
6 #include "memcache.h" |
6 #include "connection.h" |
7 #include "connection.h" |
7 #include "request.h" |
8 #include "request.h" |
8 #include "../memcache.h" |
9 #include "../memcache.h" |
9 #include "../common.h" |
10 #include "../common.h" |
10 |
11 |
11 struct memcache_server *memcache_server_alloc (struct config_endpoint *endpoint, int max_connections) { |
12 struct memcache_server *memcache_server_alloc (struct memcache *mc, struct config_endpoint *endpoint, int max_connections) { |
12 struct memcache_server *server = NULL; |
13 struct memcache_server *server = NULL; |
|
14 |
|
15 // warn if nonsensical arguments |
|
16 if (max_connections > 1 && mc->pipeline_requests) |
|
17 WARNING("only one connection will ever be used with pipeline_requests"); |
13 |
18 |
14 if ((server = calloc(1, sizeof(*server))) == NULL) |
19 if ((server = calloc(1, sizeof(*server))) == NULL) |
15 ERROR("calloc"); |
20 ERROR("calloc"); |
16 |
21 |
17 // store the vars |
22 // store the vars |
|
23 server->mc = mc; |
18 server->endpoint = endpoint; |
24 server->endpoint = endpoint; |
19 server->max_connections = max_connections; |
25 server->max_connections = max_connections; |
20 |
26 |
21 // init lists |
27 // init lists |
22 LIST_INIT(&server->conn_list); |
28 LIST_INIT(&server->conn_list); |
111 if ((req = TAILQ_FIRST(&server->req_queue)) == NULL) |
117 if ((req = TAILQ_FIRST(&server->req_queue)) == NULL) |
112 return; |
118 return; |
113 |
119 |
114 // look for idle connections to service the request |
120 // look for idle connections to service the request |
115 LIST_FOREACH(conn, &server->conn_list, connlist_node) { |
121 LIST_FOREACH(conn, &server->conn_list, connlist_node) { |
116 if (memcache_conn_is_available(conn)) { |
122 // handle pipelining as well |
|
123 while (memcache_conn_is_available(conn)) { |
117 // remove the req from the queue and execute it |
124 // remove the req from the queue and execute it |
118 TAILQ_REMOVE(&server->req_queue, req, reqqueue_node); |
125 TAILQ_REMOVE(&server->req_queue, req, reqqueue_node); |
119 |
126 |
120 // this will take care of any error handling by itself |
127 // this will take care of any error handling by itself |
121 memcache_conn_do_req(conn, req); |
128 memcache_conn_do_req(conn, req); |