Handling errors on GetQueuedCompletionStatus()

This commit is contained in:
manojampalam 2016-04-14 23:42:15 -07:00
parent 87dee940d1
commit 8f247d5c00
4 changed files with 19 additions and 4 deletions

View File

@ -90,7 +90,7 @@ BOOL WINAPI ctrl_c_handler(
int main() {
if (!StartServiceCtrlDispatcher(diapatch_table)) {
if (GetLastError() == ERROR_FAILED_SERVICE_CONTROLLER_CONNECT) {
//console app
/* console app */
SetConsoleCtrlHandler(ctrl_c_handler, TRUE);
return agent_start();
}

View File

@ -93,6 +93,7 @@ void agent_sm_process_action_queue() {
else
prev->next = tmp->next;
CloseHandle(tmp->connection);
printf("deleting %p\n", tmp);
free(tmp);
break;
}
@ -130,11 +131,19 @@ HANDLE iocp_workers[4];
DWORD WINAPI iocp_work(LPVOID lpParam) {
DWORD bytes;
struct agent_connection* con;
struct agent_connection* con = NULL;
OVERLAPPED *p_ol;
while (1) {
if (GetQueuedCompletionStatus(ioc_port, &bytes, &(ULONG_PTR)con, &p_ol, INFINITE) == FALSE)
con = NULL;
p_ol = NULL;
if (GetQueuedCompletionStatus(ioc_port, &bytes, &(ULONG_PTR)con, &p_ol, INFINITE) == FALSE) {
printf("error: %d on %p \n", GetLastError(), con);
if (con)
agent_connection_on_error(con, GetLastError());
else
return 0;
}
//printf("io on %p state %d bytes %d\n", con, con->state, bytes);
agent_connection_on_io(con, bytes, p_ol);
}

View File

@ -22,6 +22,7 @@ struct agent_connection {
};
void agent_connection_on_io(struct agent_connection*, DWORD, OVERLAPPED*);
void agent_connection_on_error(struct agent_connection* , DWORD );
void agent_connection_disconnect(struct agent_connection*);
int agent_start();

View File

@ -30,6 +30,11 @@
*/
#include "agent.h"
void agent_connection_on_error(struct agent_connection* con, DWORD error) {
con->state = DONE;
agent_cleanup_connection(con);
}
void agent_connection_on_io(struct agent_connection* con, DWORD bytes, OVERLAPPED* ol) {
/* process error */