From 8fb27e8fc68665e66634af1da598ab9657c96cf3 Mon Sep 17 00:00:00 2001 From: manojampalam Date: Tue, 12 Apr 2016 23:30:37 -0700 Subject: [PATCH] 4-12 C1 --- contrib/win32/win32compat/ssh-agent/agent.c | 64 ++++++++----------- contrib/win32/win32compat/ssh-agent/agent.h | 5 +- .../win32/win32compat/ssh-agent/connection.c | 33 ++++------ 3 files changed, 40 insertions(+), 62 deletions(-) diff --git a/contrib/win32/win32compat/ssh-agent/agent.c b/contrib/win32/win32compat/ssh-agent/agent.c index a0af35f..e2ecb6e 100644 --- a/contrib/win32/win32compat/ssh-agent/agent.c +++ b/contrib/win32/win32compat/ssh-agent/agent.c @@ -77,12 +77,13 @@ void agent_sm_process_action_queue() { 0, // client time-out NULL); - /* remove action from queue before the assigining iocp port*/ + /* remove action from queue before assigning iocp port*/ + con->next = list; + list = con; actions_remaining = InterlockedAnd(&action_queue, ~ACTION_LISTEN); CreateIoCompletionPort(h, ioc_port, con, 0); - con->next = list; - list = con; + } else { /* cleanup up a done connection*/ @@ -131,48 +132,33 @@ void agent_sm_raise(enum agent_sm_event event) { } +HANDLE iocp_workers[4]; + +DWORD WINAPI iocp_work(LPVOID lpParam) { + DWORD bytes; + struct agent_connection* con; + OVERLAPPED *p_ol; + while (1) { + GetQueuedCompletionStatus(ioc_port, &bytes, &con, &p_ol, INFINITE); + agent_connection_on_io(con, bytes, p_ol); + } +} + int agent_start() { + int i; action_queue = 0; list = NULL; ioc_port = CreateIoCompletionPort(INVALID_HANDLE_VALUE, NULL, NULL, 0); + + for (i = 0; i < 4; i++) + iocp_workers[i] = CreateThread(NULL, 0, iocp_work, NULL, 0, NULL); + action_queue = ACTION_LISTEN; agent_sm_process_action_queue(); } -void agent_listen(); -void agent_shutdown(); -void agent_cleanup_connection(struct agent_connection*); - -int agent_listen() { - - ioc_port = CreateIoCompletionPort(INVALID_HANDLE_VALUE, NULL, NULL, 0); - - - BOOL ret; - HANDLE temp; - DWORD err, bytes; - ULONG_PTR ptr; - HANDLE h = CreateNamedPipe( - pipe_name, // pipe name - PIPE_ACCESS_DUPLEX | FILE_FLAG_OVERLAPPED, // read/write access - PIPE_TYPE_MESSAGE | // message type pipe - PIPE_READMODE_MESSAGE | // message-read mode - PIPE_WAIT, // blocking mode - PIPE_UNLIMITED_INSTANCES, // max. instances - BUFSIZE, // output buffer size - BUFSIZE, // input buffer size - 0, // client time-out - NULL); - - temp = CreateIoCompletionPort(h, ioc_port, NULL, 0); - - OVERLAPPED ol, *pol; - ZeroMemory(&ol, sizeof(ol)); - ret = ConnectNamedPipe(h, &ol); - err = GetLastError(); - - GetQueuedCompletionStatus(ioc_port, &bytes, &ptr, &pol, INFINITE); - - //Sleep(INFINITE); - return 1; +void agent_shutdown() { + agent_sm_raise(SHUTDOWN); + while (list != NULL) + Sleep(100); } diff --git a/contrib/win32/win32compat/ssh-agent/agent.h b/contrib/win32/win32compat/ssh-agent/agent.h index 2124156..9ea69e8 100644 --- a/contrib/win32/win32compat/ssh-agent/agent.h +++ b/contrib/win32/win32compat/ssh-agent/agent.h @@ -3,10 +3,7 @@ int agent_start(); - -void agent_listen(); void agent_shutdown(); -void agent_cleanup_connection(struct agent_connection*); struct agent_connection { enum { @@ -19,5 +16,5 @@ struct agent_connection { struct agent_con* next; }; -void agent_connection_on_io(struct agent_connection*); +void agent_connection_on_io(struct agent_connection*, DWORD, OVERLAPPED*); void agent_connection_disconnect(struct agent_connection*); \ No newline at end of file diff --git a/contrib/win32/win32compat/ssh-agent/connection.c b/contrib/win32/win32compat/ssh-agent/connection.c index 8ced864..9d55545 100644 --- a/contrib/win32/win32compat/ssh-agent/connection.c +++ b/contrib/win32/win32compat/ssh-agent/connection.c @@ -31,25 +31,20 @@ #include "agent.h" #define BUFSIZE 5 * 1024 -static HANDLE ioc_port; - - - -ssh_agent_connection::ssh_agent_connection(HANDLE h) { - connection = h; - state = LISTENING; +void agent_connection_on_io(struct agent_connection* con, DWORD bytes, OVERLAPPED* ol) { + switch (con->state) { + case LISTENING: + break; + case READING: + break; + case WRITING: + break; + default: + DebugBreak(); + } } -ssh_agent_connection::~ssh_agent_connection() { - CloseHandle(connection); +void agent_connection_disconnect(struct agent_connection* con) { + CancelIoEx(con->connection, NULL); + DisconnectNamedPipe(con->connection); } - -void ssh_agent_connection::process_iocp(DWORD bytes_transferred, OVERLAPPED* pol) { - -} - -void ssh_agent_connection::disconnect() { - DisconnectNamedPipe(connection); - CancelIoEx(connection, NULL); -} -