/** * dispatch_accept(S, deleteto, s): * Accept a connection from the listening socket ${s} and return a dispatch * state for handling requests to the internal state ${S} and the deleter * ${deleteto}. */ struct dispatch_state * dispatch_accept(struct state * S, struct deleteto * deleteto, int s) { struct dispatch_state * D; /* Allocate space for dispatcher state. */ if ((D = malloc(sizeof(struct dispatch_state))) == NULL) goto err0; /* Initialize dispatcher. */ D->S = S; D->D = deleteto; /* Accept a connection. */ D->accepting = 1; if (network_accept(s, callback_accept, D) == NULL) goto err1; /* Success! */ return (D); err1: free(D); err0: /* Failure! */ return (NULL); }
/* Non-blocking accept, if we can have more connections. */ static int doaccept(struct accept_state * A) { int rc = 0; /* If we can, accept a new connection. */ if ((A->nconn < A->nconn_max) && (A->accept_cookie == NULL)) { if ((A->accept_cookie = network_accept(A->s, callback_gotconn, A)) == NULL) rc = -1; } /* Return success/fail status. */ return (rc); }
LRESULT app_window_proc( HWND hWnd, UINT uMsg, WPARAM wParam, LPARAM lParam ) { switch ( uMsg ) { case SOCKET_MESSAGE: switch(WSAGETSELECTEVENT(lParam)) { case FD_ACCEPT: network_accept(); return 0; case FD_READ: network_recv_invoke(wParam, &invoke_url); return 0; } MessageBox( NULL, _T("This aint right..."), THIS_TITLE, MB_ICONERROR | MB_OK | MB_TOPMOST ); return -1; default: return DefWindowProc( hWnd, uMsg, wParam, lParam ); } }
int main_forward() { int ret = 1; /* reuse the normal network setup */ if (network_init()) { /* Now accept from gdb */ if (network_accept()) { /* Now connect to remote deebe */ if (network_connect()) { while (true) { network_read(); if (network_in_buffer_total > 0) { _forward_packet(&network_out_buffer[0], &network_in_buffer[0], &network_out_buffer_total, &network_in_buffer_total); network_write_fwd(); } network_read_fwd(); if (network_in_buffer_total > 0) { _forward_packet(&network_out_buffer[0], &network_in_buffer[0], &network_out_buffer_total, &network_in_buffer_total); network_write(); } } } } network_cleanup(); } return ret; }
int main_debug() { int ret = 1; bool debugee_ok = false; /* Sets up the gdb_interface_target */ gdb_interface_init(); if (gdb_interface_target == NULL) { fprintf(stderr, "INTERNAL ERROR : gdb interface uninitalized\n"); } else { /* Check network setup */ if (network_init()) { /* Basic network ok, now setup the cmdline debuggee */ if (0 != cmdline_pid) { if (gdb_interface_target->attach) { if (RET_OK != gdb_interface_target->attach(cmdline_pid)) fprintf(stderr, "Error attaching to pid %d\n", cmdline_pid); else debugee_ok = true; } else { fprintf(stderr, "Error : Attaching to a running process is not supported\n"); } } else if (0 != cmdline_argc) { if (gdb_interface_target->open) { if (RET_OK != gdb_interface_target->open(cmdline_argc, cmdline_argv, cmdline_argv[0])) fprintf(stderr, "Error opening program %s to debug\n", cmdline_argv[0]); else debugee_ok = true; } else { fprintf(stderr, "Error : Starting a new process is not supported\n"); } } else { fprintf(stderr, "Error : no valid program to debug\n"); } if (debugee_ok) { /* Debuggee is ok, now accept connection */ /* Success */ fprintf(stdout, "Listening on port %ld\n", cmdline_port); fflush(stdout); do { if (network_accept()) { while (true) { if (_network_io(network_read, network_write, gdb_interface_packet)) { break; } } } } while (!cmdline_once); } network_cleanup(); } } gdb_interface_cleanup(); return ret; }