int main() { boost::shared_ptr<HttpServer> httpserver(new HttpServer()); httpserver->initialize("0.0.0.0", "2768"); httpserver->run(); return 0; }
void process() { unsigned short port(g_confvalue.http_listen.port); string ip(g_confvalue.http_listen.ip); short timeout(5); CHttpServer httpserver(port, ip.c_str(), timeout); if (!httpserver.work()) { logerr("httpserver start fail"); } for (; ;) { select_sleep(1000, 0); } }
int test_socket(int cmdFd, int connFd, int secs) { int ret; int mode; int port = 80; char * path = "/tmp/myvideo"; ret = screenrecorder_set_rate(cmdFd, 20); if (ret == -1) return -1; ret = screenrecorder_set_format(cmdFd, OUTPUT_FORMAT_MPEG_4); if (ret == -1) return -1; ret = screenrecorder_set_size(cmdFd, 1024, 600); if (ret == -1) return -1; PTHREAD_PARA_S *para = (PTHREAD_PARA_S *)malloc(sizeof(PTHREAD_PARA_S)); para->connFd = connFd; para->cmdFd = cmdFd; ret = screenrecorder_start(cmdFd, connFd, (LISTENFUNC)listenThreadFunc, para); if (ret == -1) return -1; ret = localwrite(cmdFd,path); if(ret < 0) return -1; ret = httpserver(cmdFd,port); if(ret < 0) return -1; sleep(secs); ret = screenrecorder_stop(cmdFd); if (ret == -1) return -1; return 0; }
TPS_PUBLIC PSHttpResponse *HttpConnection::getResponse(int index, const char *servlet, const char *body) { char *host_port; char uri[800]; char *nickname; const char *httpprotocol; ConnectionInfo *failoverList = GetFailoverList(); int len = failoverList->ConnectionInfo::GetHostPortListLen(); if (index >= len) { index = len - 1; // use the last one } host_port= (failoverList->GetHostPortList())[index]; if (IsSSL()) { httpprotocol = "https"; } else { httpprotocol = "http"; } PR_snprintf((char *)uri, 800, "%s://%s/%s", httpprotocol, host_port, servlet); RA::Debug("HttpConnection::getResponse", "Send request to host %s servlet %s", host_port, servlet); RA::Debug(LL_PER_PDU, "HttpConnection::getResponse", "uri=%s", uri); RA::Debug(LL_PER_PDU, "HttpConnection::getResponse", "host_port=%s", host_port); char *pPort = NULL; char *pPortActual = NULL; char hostName[512]; /* * Isolate the host name, account for IPV6 numeric addresses. * */ if(host_port) strncpy(hostName,host_port,512); pPort = hostName; while(1) { pPort = strchr(pPort, ':'); if (pPort) { pPortActual = pPort; pPort++; } else break; } if(pPortActual) *pPortActual = '\0'; /* * Rifle through the values for the host */ PRAddrInfo *ai; void *iter; PRNetAddr addr; int family = PR_AF_INET; ai = PR_GetAddrInfoByName(hostName, PR_AF_UNSPEC, PR_AI_ADDRCONFIG); if (ai) { printf("%s\n", PR_GetCanonNameFromAddrInfo(ai)); iter = NULL; while ((iter = PR_EnumerateAddrInfo(iter, ai, 0, &addr)) != NULL) { char buf[512]; PR_NetAddrToString(&addr, buf, sizeof buf); RA::Debug( LL_PER_PDU, "HttpConnection::getResponse: ", "Sending addr -- Msg='%s'\n", buf ); family = PR_NetAddrFamily(&addr); RA::Debug( LL_PER_PDU, "HttpConnection::getResponse: ", "Sending family -- Msg='%d'\n", family ); break; } PR_FreeAddrInfo(ai); } PSHttpServer httpserver(host_port, family); nickname = GetClientNickname(); if (IsSSL()) httpserver.setSSL(PR_TRUE); else httpserver.setSSL(PR_FALSE); PSHttpRequest httprequest(&httpserver, uri, HTTP11, 0); if (IsSSL()) { httprequest.setSSL(PR_TRUE); if (nickname != NULL) { httprequest.setCertNickName(nickname); } else { return NULL; } } else httprequest.setSSL(PR_FALSE); httprequest.setMethod("POST"); if (body != NULL) { httprequest.setBody( strlen(body), body); } httprequest.addHeader( "Content-Type", "application/x-www-form-urlencoded" ); if (m_headers != NULL) { for (int i=0; i<m_headers->Size(); i++) { char *name = m_headers->GetNameAt(i); httprequest.addHeader(name, m_headers->GetValue(name)); } } if (IsKeepAlive()) httprequest.addHeader( "Connection", "keep-alive" ); HttpEngine httpEngine; return httpEngine.makeRequest(httprequest, httpserver, (PRIntervalTime)GetTimeout(), PR_FALSE /*expectChunked*/); }