/** * @brief VNC server thread process * @param argument: not used * @retval none */ static void _ServerThread(void const * argument) { int s; u32_t AddrLen; U16 Port; /* Prepare socket (one time setup) Default port for VNC is is 590x, where x is the 0-based layer index */ Port = 5900 + _Context.ServerIndex; /* Loop until we get a socket into listening state */ do { s = _ListenAtTcpAddr(Port); if (s != -1) { break; } vTaskDelay(100); // Try again } while (1); /* Loop once per client and create a thread for the actual server */ while (1) { /* Wait for an incoming connection */ AddrLen = sizeof(_Addr); _Sock = accept(s, (struct sockaddr*)&_Addr, &AddrLen); /* Run the actual server */ GUI_VNC_Process(&_Context, _Send, _Recv, (void *)_Sock); /* Close the connection */ closesocket(_Sock); memset(&_Addr, 0, sizeof(struct sockaddr_in)); } }
/********************************************************************* * * _ServerTask * * Function description * This routine is the actual server task. * It executes some one-time init code, then runs in an ednless loop. * It therefor does not terminate. * In the endless loop it * - Waits for a conection from a client * - Runs the server code * - Closes the connection */ static void _ServerTask(void) { int s, sock; short Port; struct sockaddr_in addr_in; const int one = 1; /* Prepare socket (one time setup) */ Port = 5900 + _Context.ServerIndex; /* Default port for VNC is is 590x, where x is the 0-based layer index */ addr_in.sin_family = AF_INET; addr_in.sin_port = htons(Port); addr_in.sin_addr.s_addr = INADDR_ANY; s = socket(AF_INET, SOCK_STREAM, 0); if (s < 0) { return; /* Error ... We are done with this task */ } if (setsockopt(s, SOL_SOCKET, SO_REUSEADDR, (const char *) &one, sizeof(one)) < 0) { closesocket(s); return; /* Error ... We are done with this task */ } if (bind(s, (struct sockaddr *)&addr_in, sizeof(addr_in))) { closesocket(s); return; /* Error ... We are done with this task */ } if (listen(s, 1)) { closesocket(s); return; /* Error ... We are done with this task */ } /* Endless loop. We run thru it once for every client connecting to us */ while (1) { struct sockaddr addr; int addrlen; /* Wait for an incoming connection */ addrlen = sizeof(addr); if ((sock = accept(s, &addr, &addrlen)) < 0) { return; /* Error ... We are done with this task */ } /* Disable Nagle's algorithm - improves performance (optional) */ { const int zero = 0; setsockopt(sock, SOL_SOCKET, SO_NAGLE, (const char *) &zero, sizeof(zero)); } /* Run the actual server */ GUI_VNC_Process(&_Context, _Send, _Recv, (void*)sock); /* Close the connection */ closesocket(sock); } }
/** * @brief VNC server thread process * @param argument: not used * @retval none */ static void VNC_Process( void) { static int s; static uint8_t Is_SocketAssigned = 0; u32_t AddrLen; U16 Port; if(Is_SocketAssigned == 0) { Is_SocketAssigned = 1; /* Prepare socket (one time setup) Default port for VNC is is 590x, where x is the 0-based layer index */ Port = 5900 + _Context.ServerIndex; /* Loop until we get a socket into listening state */ do { s = _ListenAtTcpAddr(Port); if (s != -1) { break; } vTaskDelay(100); /* Try again */ } while (1); } VNC_SERVER_StatusChanged(VNC_CONN_ESTABLISHED); /* Loop once per client and create a thread for the actual server */ while (VNC_State == VNC_PROCESS) { /* Wait for an incoming connection */ AddrLen = sizeof(_Addr); Connection_accepted = 1; if ((_Sock = accept(s, (struct sockaddr*)&_Addr, &AddrLen)) < 1) { closesocket(_Sock); vTaskDelay(100); continue; /* Error */ } Connection_accepted = 0; VNC_SERVER_LogMessage ("Connected to VNC Client"); GUI_VNC_Process(&_Context, _Send, _Recv, (void *)_Sock); VNC_SERVER_LogMessage ((char *)iptxt); /* Close the connection */ closesocket(_Sock); } }
/********************************************************************* * * _ServerTask * * Function description * This routine is the actual server task. * It executes some one-time init code, then runs in an ednless loop. * It therefor does not terminate. * In the endless loop it * - Waits for a conection from a client * - Runs the server code * - Closes the connection */ static void _ServerTask(void * pvParameters) { int s, Sock; u32_t AddrLen; U16 Port; // // Prepare socket (one time setup) // Port = 5900 + _Context.ServerIndex; // Default port for VNC is is 590x, where x is the 0-based layer index // // Loop until we get a socket into listening state // do { s = _ListenAtTcpAddr(Port); if (s != -1) { break; } vTaskDelay(100); // Try again } while (1); // // Loop once per client and create a thread for the actual server // while (1) { // // Wait for an incoming connection // AddrLen = sizeof(_Addr); Sock = accept(s, (struct sockaddr*)&_Addr, &AddrLen); // // Run the actual server // GUI_VNC_Process(&_Context, _Send, _Recv, (void *)Sock); // // Close the connection // closesocket(Sock); memset(&_Addr, 0, sizeof(struct sockaddr_in)); } }
/********************************************************************* * * _ServerTask * * Function description * This routine is the actual server task. * It executes some one-time init code, then runs in an ednless loop. * It therefor does not terminate. * In the endless loop it * - Waits for a conection from a client * - Runs the server code * - Closes the connection */ static void _ServerTask(void) { //int s, sock; //JLA, s made global int sock; short Port; struct sockaddr_in addr_in; const int one = 1; /* Prepare socket (one time setup) */ Port = 5900 + _Context.ServerIndex; /* Default port for VNC is is 590x, where x is the 0-based layer index */ addr_in.sin_family = AF_INET; addr_in.sin_port = htons(Port); addr_in.sin_addr.s_addr = INADDR_ANY; s = socket(AF_INET, SOCK_STREAM, 0); if (s < 0) { return; /* Error ... We are done with this task */ } if (setsockopt(s, SOL_SOCKET, SO_REUSEADDR, (const char *) &one, sizeof(one)) < 0) { closesocket(s); return; /* Error ... We are done with this task */ } if (bind(s, (struct sockaddr *)&addr_in, sizeof(addr_in))) { closesocket(s); return; /* Error ... We are done with this task */ } if (listen(s, 1)) { closesocket(s); return; /* Error ... We are done with this task */ } /* Endless loop. We run thru it once for every client connecting to us */ while (1) { struct sockaddr addr; int addrlen; int rc; /* Wait for an incoming connection */ addrlen = sizeof(addr); if ((sock = accept(s, &addr, &addrlen)) < 0) { return; /* Error ... We are done with this task */ } /* Disable Nagle's algorithm - improves performance (optional) */ { const int zero = 0; rc = setsockopt(sock, SOL_SOCKET, SO_NAGLE, (const char *) &zero, sizeof(zero)); if (rc) { OS_DebugSendString("MPCVNCServer: Failed to set SO_NAGLE"); /*OS*/ /* output to embOSView terminal window */ } } /* -----------------14-09-2005 15:49----------------- * set socket receive timeout to avoid a socket * connection to hang in the VNC process * --------------------------------------------------*/ { struct timeval timeout; timeout.tv_sec = 20; timeout.tv_usec = 0; if (rc == 0) { rc = setsockopt(sock, SOL_SOCKET, SO_RCV_TIMEO, (const char *)&timeout, sizeof(timeout)); if (rc) { OS_DebugSendString("MPCVNCServer: Failed to set SO_RCV_TIMEO"); /*OS*/ /* output to embOSView terminal window */ } } } /* Run the actual server */ if (rc == 0) { GUI_VNC_Process(&_Context, _Send, _Recv, (void*)sock); } /* Close the connection */ closesocket(sock); } }