This commit is contained in:
manojampalam 2016-04-12 23:30:37 -07:00
parent d3640ddd8e
commit 8fb27e8fc6
3 changed files with 40 additions and 62 deletions

View File

@ -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);
}

View File

@ -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*);

View File

@ -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);
}