• Home
  • Raw
  • Download

Lines Matching refs:srv

23 	struct http_server *srv;  member
45 struct http_server *srv = req->srv; in http_request_cb() local
51 srv->cb(srv->cb_ctx, req); in http_request_cb()
61 static struct http_request * http_request_init(struct http_server *srv, int fd, in http_request_init() argument
66 if (srv->request_count >= HTTP_SERVER_MAX_CONNECTIONS) { in http_request_init()
75 req->srv = srv; in http_request_init()
94 struct http_server *srv; in http_request_deinit() local
99 srv = req->srv; in http_request_deinit()
101 r = srv->requests; in http_request_deinit()
107 srv->requests = r->next; in http_request_deinit()
108 srv->request_count--; in http_request_deinit()
203 struct http_server *srv = eloop_ctx; in http_server_cb() local
207 conn = accept(srv->fd, (struct sockaddr *) &addr, &addr_len); in http_server_cb()
216 req = http_request_init(srv, conn, &addr); in http_server_cb()
222 req->next = srv->requests; in http_server_cb()
223 srv->requests = req; in http_server_cb()
224 srv->request_count++; in http_server_cb()
234 struct http_server *srv; in http_server_init() local
237 srv = os_zalloc(sizeof(*srv)); in http_server_init()
238 if (srv == NULL) in http_server_init()
240 srv->cb = cb; in http_server_init()
241 srv->cb_ctx = cb_ctx; in http_server_init()
243 srv->fd = socket(AF_INET, SOCK_STREAM, 0); in http_server_init()
244 if (srv->fd < 0) in http_server_init()
247 if (setsockopt(srv->fd, SOL_SOCKET, SO_REUSEADDR, &on, sizeof(on)) < 0) in http_server_init()
255 if (fcntl(srv->fd, F_SETFL, O_NONBLOCK) < 0) in http_server_init()
258 srv->port = 49152; in http_server_init()
260 srv->port = port; in http_server_init()
267 sin.sin_port = htons(srv->port); in http_server_init()
268 if (bind(srv->fd, (struct sockaddr *) &sin, sizeof(sin)) == 0) in http_server_init()
272 if (++srv->port == 65535 || port >= 0) in http_server_init()
277 "%s", srv->port, strerror(errno)); in http_server_init()
280 if (listen(srv->fd, 10 /* max backlog */) < 0 || in http_server_init()
281 fcntl(srv->fd, F_SETFL, O_NONBLOCK) < 0 || in http_server_init()
282 eloop_register_sock(srv->fd, EVENT_TYPE_READ, http_server_cb, in http_server_init()
283 srv, NULL)) in http_server_init()
287 inet_ntoa(*addr), srv->port); in http_server_init()
289 return srv; in http_server_init()
292 http_server_deinit(srv); in http_server_init()
297 void http_server_deinit(struct http_server *srv) in http_server_deinit() argument
299 if (srv == NULL) in http_server_deinit()
301 if (srv->fd >= 0) { in http_server_deinit()
302 eloop_unregister_sock(srv->fd, EVENT_TYPE_READ); in http_server_deinit()
303 close(srv->fd); in http_server_deinit()
305 http_request_free_all(srv->requests); in http_server_deinit()
307 os_free(srv); in http_server_deinit()
311 int http_server_get_port(struct http_server *srv) in http_server_get_port() argument
313 return srv->port; in http_server_get_port()