Lines Matching defs:context
129 static void mpm_recycle_completion_context(winnt_conn_ctx_t *context)
131 /* Recycle the completion context.
133 * - put the context on the queue to be consumed by the accept thread
135 * context->accept_socket may be in a disconnected but reusable
138 if (context) {
139 apr_pool_clear(context->ptrans);
140 context->ba = apr_bucket_alloc_create(context->ptrans);
141 context->next = NULL;
142 ResetEvent(context->overlapped.hEvent);
145 qtail->next = context;
147 qhead = context;
150 qtail = context;
158 winnt_conn_ctx_t *context = NULL;
162 /* Grab a context off the queue */
165 context = qhead;
174 if (!context) {
175 /* We failed to grab a context off the queue, consider allocating
191 /* Wait for a worker to free a context. Once per second, give
193 * succeeds, get the context off the queue. It must be
204 "free context within 1 second");
212 "WaitForSingleObject failed to get free context");
217 /* Allocate another context.
225 context = (winnt_conn_ctx_t *)apr_pcalloc(pchild,
229 context->overlapped.hEvent = CreateEvent(NULL, TRUE,
231 if (context->overlapped.hEvent == NULL) {
245 rv = apr_pool_create_ex(&context->ptrans, pchild, NULL,
251 CloseHandle(context->overlapped.hEvent);
256 apr_allocator_owner_set(allocator, context->ptrans);
257 apr_pool_tag(context->ptrans, "transaction");
259 context->accept_socket = INVALID_SOCKET;
260 context->ba = apr_bucket_alloc_create(context->ptrans);
267 /* Got a context from the queue */
272 return context;
296 winnt_conn_ctx_t *context = NULL;
404 if (!context) {
407 context = mpm_get_completion_context(&timeout);
408 if (!context) {
431 if (context->accept_socket == INVALID_SOCKET) {
432 context->accept_socket = socket(ss_listen.ss_family, SOCK_STREAM,
434 context->socket_family = ss_listen.ss_family;
436 else if (context->socket_family != ss_listen.ss_family) {
437 closesocket(context->accept_socket);
438 context->accept_socket = socket(ss_listen.ss_family, SOCK_STREAM,
440 context->socket_family = ss_listen.ss_family;
443 if (context->accept_socket == INVALID_SOCKET)
444 context->accept_socket = socket(AF_INET, SOCK_STREAM, IPPROTO_TCP);
447 if (context->accept_socket == INVALID_SOCKET) {
458 buf = apr_bucket_alloc(len, context->ba);
463 buf = context->buff;
466 /* AcceptEx on the completion context. The completion context will be
469 if (!lpfnAcceptEx(nlsd, context->accept_socket, buf, len,
471 &context->overlapped)) {
481 closesocket(context->accept_socket);
482 context->accept_socket = INVALID_SOCKET;
497 closesocket(context->accept_socket);
498 context->accept_socket = INVALID_SOCKET;
518 closesocket(context->accept_socket);
519 context->accept_socket = INVALID_SOCKET;
536 events[0] = context->overlapped.hEvent;
543 if ((context->accept_socket != INVALID_SOCKET) &&
544 !GetOverlappedResult((HANDLE)context->accept_socket,
545 &context->overlapped,
550 closesocket(context->accept_socket);
551 context->accept_socket = INVALID_SOCKET;
556 closesocket(context->accept_socket);
557 context->accept_socket = INVALID_SOCKET;
563 if (context->accept_socket == INVALID_SOCKET) {
576 if (setsockopt(context->accept_socket, SOL_SOCKET,
589 &context->sa_server, &context->sa_server_len,
590 &context->sa_client, &context->sa_client_len);
593 * and pass to worker_main as context->overlapped.Pointer
599 apr_bucket_free, context->ba);
602 context->overlapped.Pointer = b;
608 context->overlapped.Pointer = NULL;
614 if (context->accept_socket != INVALID_SOCKET)
615 closesocket(context->accept_socket);
636 context->sa_server = (void *) context->buff;
637 context->sa_server_len = sizeof(context->buff) / 2;
638 context->sa_client_len = context->sa_server_len;
639 context->sa_client = (void *) (context->buff
640 + context->sa_server_len);
642 context->accept_socket = accept(nlsd, context->sa_server,
643 &context->sa_server_len);
645 if (context->accept_socket == INVALID_SOCKET) {
682 WSAEventSelect(context->accept_socket, 0, 0);
683 context->overlapped.Pointer = NULL;
686 context->sa_server_len = sizeof(context->buff) / 2;
687 if (getsockname(context->accept_socket, context->sa_server,
688 &context->sa_server_len) == SOCKET_ERROR) {
693 if ((getpeername(context->accept_socket, context->sa_client,
694 &context->sa_client_len)) == SOCKET_ERROR) {
697 memset(&context->sa_client, '\0', sizeof(context->sa_client));
701 sockinfo.os_sock = &context->accept_socket;
702 sockinfo.local = context->sa_server;
703 sockinfo.remote = context->sa_client;
704 sockinfo.family = context->sa_server->sa_family;
712 ioctlsocket(context->accept_socket, FIONBIO, &zero);
713 setsockopt(context->accept_socket, SOL_SOCKET, SO_RCVTIMEO,
715 setsockopt(context->accept_socket, SOL_SOCKET, SO_SNDTIMEO,
717 apr_os_sock_make(&context->sock, &sockinfo, context->ptrans);
724 &context->overlapped);
725 context = NULL;
741 static winnt_conn_ctx_t *winnt_get_connection(winnt_conn_ctx_t *context)
752 mpm_recycle_completion_context(context);
772 context = CONTAINING_RECORD(pol, winnt_conn_ctx_t, overlapped);
785 return context;
793 winnt_conn_ctx_t *context = ap_get_module_config(c->conn_config,
795 if (context == NULL || (e = context->overlapped.Pointer) == NULL)
816 winnt_conn_ctx_t *context = NULL;
831 context = winnt_get_connection(context);
833 if (!context) {
846 e = context->overlapped.Pointer;
848 ap_create_sb_handle(&sbh, context->ptrans, 0, thread_num);
849 c = ap_run_create_connection(context->ptrans, ap_server_conf,
850 context->sock, thread_num, sbh,
851 context->ba);
855 context->accept_socket = INVALID_SOCKET;
863 apr_os_thread_put(&thd, &osthd, context->ptrans);
866 /* follow ap_process_connection(c, context->sock) logic
871 rc = ap_run_pre_connection(c, context->sock);
880 ap_set_module_config(c->conn_config, &mpm_winnt_module, context);
887 apr_socket_opt_get(context->sock, APR_SO_DISCONNECTED, &disconnected);
890 context->accept_socket = INVALID_SOCKET;