X-Git-Url: https://git.stg.codes/stg.git/blobdiff_plain/641204dfbdb9fc870cdd2e7f9e3169a44693e7bf..5557e008104be6b01ece7c968a25ad2830717d55:/projects/sgauth/web.cpp?ds=sidebyside diff --git a/projects/sgauth/web.cpp b/projects/sgauth/web.cpp index caec33a0..01660b61 100644 --- a/projects/sgauth/web.cpp +++ b/projects/sgauth/web.cpp @@ -23,14 +23,16 @@ $Date: 2010/03/15 12:58:17 $ */ -#include -#include -#include #include +#include +#include +#include +#include + +#include "stg/common.h" +#include "stg/ia.h" #include "web.h" -#include "common.h" -#include "ia_auth_c.h" extern WEB * web; extern IA_CLIENT_PROT * clnp; @@ -42,10 +44,15 @@ extern IA_CLIENT_PROT * clnp; //--------------------------------------------------------------------------- #ifndef WIN32 void * RunWeb(void *) +{ +sigset_t signalSet; +sigfillset(&signalSet); +pthread_sigmask(SIG_BLOCK, &signalSet, NULL); + #else unsigned long WINAPI RunWeb(void *) -#endif { +#endif while (1) web->Run(); return NULL; @@ -56,8 +63,7 @@ WEB::WEB() listenSocket(0), outerSocket(0), refreshPeriod(0), - listenWebAddr(0), - outerAddrLen(0) + listenWebAddr(0) { #ifdef WIN32 res = WSAStartup(MAKEWORD(2,0), &wsaData); @@ -67,6 +73,8 @@ for (int i = 0; i < DIR_NUM; i++) dirName[i] = "-"; refreshPeriod = 5; + +memset(&ls, 0, sizeof(ls)); } //--------------------------------------------------------------------------- void WEB::Start() @@ -89,13 +97,14 @@ pthread_create(&thread, NULL, RunWeb, NULL); void WEB::PrepareNet() { listenSocket = socket(PF_INET, SOCK_STREAM, 0); + +struct sockaddr_in listenAddr; listenAddr.sin_family = AF_INET; listenAddr.sin_port = htons(LISTEN_PORT); listenAddr.sin_addr.s_addr = listenWebAddr; -int lng = 1; - #ifndef WIN32 +int lng = 1; if (0 != setsockopt(listenSocket, SOL_SOCKET, SO_REUSEADDR, &lng, 4)) { printf("Setsockopt Fail\n"); @@ -120,8 +129,6 @@ if (res == -1) printf("Listen failed.\n"); exit(0); } - -outerAddrLen = sizeof(outerAddr); } //--------------------------------------------------------------------------- void WEB::SetRefreshPagePeriod(int p) @@ -142,6 +149,14 @@ PrepareNet(); char recvBuffer[4096]; while (1) { + struct sockaddr_in outerAddr; + + #ifndef WIN32 + socklen_t outerAddrLen = sizeof(outerAddr); + #else + int outerAddrLen = sizeof(outerAddr); + #endif + outerSocket = accept(listenSocket, (struct sockaddr*)&outerAddr, &outerAddrLen); if (outerSocket == -1) { @@ -174,7 +189,8 @@ while (1) #ifdef WIN32 Sleep(1000); #else - usleep(1000000); + struct timespec ts = {1, 0}; + nanosleep(&ts, NULL); #endif exit(0); } @@ -278,7 +294,7 @@ for (j = 0; j < DIR_NUM; j++) { if (dirName[j][0] == 0) continue; - string s; + std::string s; KOIToWin(dirName[j], &s);// +++++++++ sigsegv ========== TODO too long dir name crashes sgauth sprintf(str, " %s\n", rowNum++, s.c_str()); send(outerSocket, str, strlen(str), 0); @@ -372,7 +388,7 @@ if (!messages.empty()) sprintf(str," \n"); send(outerSocket, str, strlen(str), 0); - list::reverse_iterator it; + std::list::reverse_iterator it; it = messages.rbegin(); while (it != messages.rend()) { @@ -417,12 +433,12 @@ send(outerSocket, replyFooter, strlen(replyFooter), 0); return 0; } //--------------------------------------------------------------------------- -void WEB::SetDirName(const string & dn, int n) +void WEB::SetDirName(const std::string & dn, int n) { web->dirName[n] = dn; } //--------------------------------------------------------------------------- -void WEB::AddMessage(const string & message, int type) +void WEB::AddMessage(const std::string & message, int type) { time_t t = time(NULL); STG_MESSAGE m;