int handleNetworkDatagramEvents(WPARAM wParam,LPARAM lParam) { switch(WSAGETSELECTEVENT(lParam)) { case FD_WRITE: javanotify_datagram_event( JAVACALL_EVENT_DATAGRAM_SENDTO_COMPLETED, (javacall_handle)wParam, (WSAGETSELECTERROR(lParam) == 0) ? JAVACALL_OK : JAVACALL_FAIL); #ifdef ENABLE_NETWORK_TRACING fprintf(stderr, "[UDP] FD_WRITE)\n"); #endif return 0; case FD_READ: #ifdef ENABLE_JSR_120 if (JAVACALL_OK == try_process_wma_emulator((javacall_handle)wParam)) { return 0; } #endif javanotify_datagram_event( JAVACALL_EVENT_DATAGRAM_RECVFROM_COMPLETED, (javacall_handle)wParam, (WSAGETSELECTERROR(lParam) == 0) ? JAVACALL_OK : JAVACALL_FAIL); #ifdef ENABLE_NETWORK_TRACING fprintf(stderr, "[UDP] FD_READ)\n"); #endif return 0; case FD_CLOSE: #ifdef ENABLE_NETWORK_TRACING fprintf(stderr, "[UDP] FD_CLOSE)\n"); #endif return 0; default: #ifdef ENABLE_NETWORK_TRACING fprintf(stderr, "[UDP] unsolicited event %d)\n", WSAGETSELECTEVENT(lParam)); #endif break; }//end switch return 0; }
static LRESULT CALLBACK WndProc (HWND hwnd, UINT iMsg, WPARAM wParam, LPARAM lParam) { //check if udp or tcp int level = SOL_SOCKET; int opttarget; int optname; int optsize = sizeof(optname); switch (iMsg) { case WM_CLOSE: /* * Handle the "X" (close window) button by sending the AMS a shutdown * event. */ PostQuitMessage (0); javanotify_shutdown(); return 0; case WM_TIMER: // Stop the timer from repeating the WM_TIMER message. KillTimer(hwnd, wParam); return 0; case WM_NETWORK: #ifdef ENABLE_NETWORK_TRACING fprintf(stderr, "Got WM_NETWORK("); fprintf(stderr, "descriptor = %d, ", (int)wParam); fprintf(stderr, "status = %d, ", WSAGETSELECTERROR(lParam)); #endif optname = SO_TYPE; if (0 != getsockopt((SOCKET)wParam, SOL_SOCKET, optname,(char*)&opttarget, &optsize)) { #ifdef ENABLE_NETWORK_TRACING fprintf(stderr, "getsocketopt error)\n"); #endif } if(opttarget == SOCK_STREAM) { switch (WSAGETSELECTEVENT(lParam)) { case FD_CONNECT: /* Change this to a write. */ javanotify_socket_event( JAVACALL_EVENT_SOCKET_OPEN_COMPLETED, (javacall_handle)wParam, (WSAGETSELECTERROR(lParam) == 0) ? JAVACALL_OK : JAVACALL_FAIL); #ifdef ENABLE_NETWORK_TRACING fprintf(stderr, "[TCP] FD_CONNECT)\n"); #endif return 0; case FD_WRITE: javanotify_socket_event( JAVACALL_EVENT_SOCKET_SEND, (javacall_handle)wParam, (WSAGETSELECTERROR(lParam) == 0) ? JAVACALL_OK : JAVACALL_FAIL); javanotify_socket_event( JAVACALL_EVENT_SERVER_SOCKET_ACCEPT_COMPLETED, (javacall_handle)wParam, (WSAGETSELECTERROR(lParam) == 0) ? JAVACALL_OK : JAVACALL_FAIL); #ifdef ENABLE_NETWORK_TRACING fprintf(stderr, "[TCP] FD_WRITE)\n"); #endif return 0; case FD_ACCEPT: javanotify_server_socket_event( JAVACALL_EVENT_SERVER_SOCKET_ACCEPT_COMPLETED, (javacall_handle)wParam, (javacall_handle)wParam, (WSAGETSELECTERROR(lParam) == 0) ? JAVACALL_OK : JAVACALL_FAIL); #ifdef ENABLE_NETWORK_TRACING fprintf(stderr, "[TCP] FD_ACCEPT, "); #endif case FD_READ: javanotify_socket_event( JAVACALL_EVENT_SOCKET_RECEIVE, (javacall_handle)wParam, (WSAGETSELECTERROR(lParam) == 0) ? JAVACALL_OK : JAVACALL_FAIL); #ifdef ENABLE_NETWORK_TRACING fprintf(stderr, "[TCP] FD_READ)\n"); #endif return 0; case FD_CLOSE: javanotify_socket_event( JAVACALL_EVENT_SOCKET_CLOSE_COMPLETED, (javacall_handle)wParam, (WSAGETSELECTERROR(lParam) == 0) ? JAVACALL_OK : JAVACALL_FAIL); #ifdef ENABLE_NETWORK_TRACING fprintf(stderr, "[TCP] FD_CLOSE)\n"); #endif return 0; default: #ifdef ENABLE_NETWORK_TRACING fprintf(stderr, "[TCP] unsolicited event %d)\n", WSAGETSELECTEVENT(lParam)); #endif break; }//end switch }//SOCK_STREAM else if (opttarget == SOCK_DGRAM) { switch (WSAGETSELECTEVENT(lParam)) { case FD_WRITE: javanotify_datagram_event( JAVACALL_EVENT_DATAGRAM_SENDTO_COMPLETED, (javacall_handle)wParam, (WSAGETSELECTERROR(lParam) == 0) ? JAVACALL_OK : JAVACALL_FAIL); #ifdef ENABLE_NETWORK_TRACING fprintf(stderr, "[UDP] FD_WRITE)\n"); #endif return 0; case FD_READ: #if ENABLE_JSR_120 if (JAVACALL_OK == try_process_wma_emulator((javacall_handle)wParam)) { return 0; } #endif javanotify_datagram_event( JAVACALL_EVENT_DATAGRAM_RECVFROM_COMPLETED, (javacall_handle)wParam, (WSAGETSELECTERROR(lParam) == 0) ? JAVACALL_OK : JAVACALL_FAIL); #ifdef ENABLE_NETWORK_TRACING fprintf(stderr, "[UDP] FD_READ)\n"); #endif return 0; case FD_CLOSE: #ifdef ENABLE_NETWORK_TRACING fprintf(stderr, "[UDP] FD_CLOSE)\n"); #endif return 0; default: #ifdef ENABLE_NETWORK_TRACING fprintf(stderr, "[UDP] unsolicited event %d)\n", WSAGETSELECTEVENT(lParam)); #endif break; }//end switch }//end UDP return 0; case WM_HOST_RESOLVED: #ifdef ENABLE_TRACE_NETWORKING fprintf(stderr, "Got Windows event WM_HOST_RESOLVED \n"); #endif javanotify_socket_event( JAVACALL_EVENT_NETWORK_GETHOSTBYNAME_COMPLETED, (javacall_handle)wParam, (WSAGETSELECTERROR(lParam) == 0) ? JAVACALL_OK : JAVACALL_FAIL); return 0; } return DefWindowProc (hwnd, iMsg, wParam, lParam); }