Lines Matching refs:context

148   connection_context_t* context;  in create_connection_context()  local
150 context = (connection_context_t*) malloc(sizeof *context); in create_connection_context()
151 ASSERT_NOT_NULL(context); in create_connection_context()
153 context->sock = sock; in create_connection_context()
154 context->is_server_connection = is_server_connection; in create_connection_context()
155 context->read = 0; in create_connection_context()
156 context->sent = 0; in create_connection_context()
157 context->open_handles = 0; in create_connection_context()
158 context->events = 0; in create_connection_context()
159 context->delayed_events = 0; in create_connection_context()
160 context->got_fin = 0; in create_connection_context()
161 context->sent_fin = 0; in create_connection_context()
162 context->got_disconnect = 0; in create_connection_context()
164 r = uv_poll_init_socket(uv_default_loop(), &context->poll_handle, sock); in create_connection_context()
165 context->open_handles++; in create_connection_context()
166 context->poll_handle.data = context; in create_connection_context()
169 r = uv_timer_init(uv_default_loop(), &context->timer_handle); in create_connection_context()
170 context->open_handles++; in create_connection_context()
171 context->timer_handle.data = context; in create_connection_context()
174 return context; in create_connection_context()
179 connection_context_t* context = (connection_context_t*) handle->data; in connection_close_cb() local
181 if (--context->open_handles == 0) { in connection_close_cb()
182 if (test_mode == DUPLEX || context->is_server_connection) { in connection_close_cb()
183 ASSERT_EQ(context->read, TRANSFER_BYTES); in connection_close_cb()
185 ASSERT_OK(context->read); in connection_close_cb()
188 if (test_mode == DUPLEX || !context->is_server_connection) { in connection_close_cb()
189 ASSERT_EQ(context->sent, TRANSFER_BYTES); in connection_close_cb()
191 ASSERT_OK(context->sent); in connection_close_cb()
196 free(context); in connection_close_cb()
201 static void destroy_connection_context(connection_context_t* context) { in destroy_connection_context() argument
202 uv_close((uv_handle_t*) &context->poll_handle, connection_close_cb); in destroy_connection_context()
203 uv_close((uv_handle_t*) &context->timer_handle, connection_close_cb); in destroy_connection_context()
208 connection_context_t* context = (connection_context_t*) handle->data; local
213 ASSERT(events & context->events);
214 ASSERT(!(events & ~context->events));
216 new_events = context->events;
228 r = recv(context->sock, buffer, sizeof buffer, 0);
233 context->read += r;
236 context->got_fin = 1;
250 r = recv(context->sock, buffer, sizeof buffer, 0);
256 context->read += r;
261 context->got_fin = 1;
277 if (!uv_is_active((uv_handle_t*) &context->timer_handle)) {
278 context->delayed_events = UV_READABLE;
279 uv_timer_start(&context->timer_handle, delay_timer_cb, 10, 0);
281 context->delayed_events |= UV_READABLE;
287 uv_poll_start(&context->poll_handle, UV_WRITABLE, connection_poll_cb);
288 uv_poll_start(&context->poll_handle, UV_READABLE, connection_poll_cb);
289 context->events = UV_READABLE;
298 if (context->sent < TRANSFER_BYTES &&
299 !(test_mode == UNIDIRECTIONAL && context->is_server_connection)) {
309 int send_bytes = MIN(TRANSFER_BYTES - context->sent, sizeof buffer);
313 r = send(context->sock, buffer, send_bytes, 0);
323 context->sent += r;
333 int send_bytes = MIN(TRANSFER_BYTES - context->sent, sizeof buffer);
337 r = send(context->sock, buffer, send_bytes, 0);
348 context->sent += r;
350 while (context->sent < TRANSFER_BYTES) {
351 send_bytes = MIN(TRANSFER_BYTES - context->sent, sizeof buffer);
355 r = send(context->sock, buffer, send_bytes, 0);
364 context->sent += r;
376 if (!uv_is_active((uv_handle_t*) &context->timer_handle)) {
377 context->delayed_events = UV_WRITABLE;
378 uv_timer_start(&context->timer_handle, delay_timer_cb, 100, 0);
380 context->delayed_events |= UV_WRITABLE;
386 uv_poll_start(&context->poll_handle,
389 uv_poll_start(&context->poll_handle,
392 context->events = UV_WRITABLE;
403 r = shutdown(context->sock, SD_SEND);
405 r = shutdown(context->sock, SHUT_WR);
408 context->sent_fin = 1;
414 context->got_disconnect = 1;
419 if (context->got_fin && context->sent_fin && context->got_disconnect) {
421 if (context->got_fin && context->sent_fin) {
424 close_socket(context->sock);
425 destroy_connection_context(context);
426 context->events = 0;
428 } else if (new_events != context->events) {
430 context->events = new_events;
435 if (context->events != 0) {
444 connection_context_t* context = (connection_context_t*) timer->data; local
451 ASSERT(context->delayed_events != 0);
452 context->events |= context->delayed_events;
453 context->delayed_events = 0;
455 r = uv_poll_start(&context->poll_handle,
456 context->events,
465 server_context_t* context; local
467 context = (server_context_t*) malloc(sizeof *context);
468 ASSERT_NOT_NULL(context);
470 context->sock = sock;
471 context->connections = 0;
473 r = uv_poll_init_socket(uv_default_loop(), &context->poll_handle, sock);
474 context->poll_handle.data = context;
477 return context;
482 server_context_t* context = (server_context_t*) handle->data; local
483 free(context);
487 static void destroy_server_context(server_context_t* context) { argument
488 uv_close((uv_handle_t*) &context->poll_handle, server_close_cb);
524 server_context_t* context; local
531 context = create_server_context(sock);
536 r = uv_poll_start(&context->poll_handle, UV_READABLE, server_poll_cb);
543 connection_context_t* context; local
552 context = create_connection_context(sock, 0);
554 context->events = UV_READABLE | UV_WRITABLE | UV_DISCONNECT;
555 r = uv_poll_start(&context->poll_handle,