本文整理汇总了C++中HTTPServer类的典型用法代码示例。如果您正苦于以下问题:C++ HTTPServer类的具体用法?C++ HTTPServer怎么用?C++ HTTPServer使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。
在下文中一共展示了HTTPServer类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: echo_recv
static err_t echo_recv(void *arg, struct tcp_pcb *pcb, struct pbuf *p, err_t err)
{
os_printf("Echo recv!\n");
HTTPServer* self = (HTTPServer*) arg;
int i;
int len;
char *pc;
if (err == ERR_OK && p != NULL) {
// Inform TCP that we have taken the data.
tcp_recved(pcb, p->tot_len);
os_printf("TCP recv no error!\n");
//pointer to the pay load
pc = (char *)p->payload;
//size of the pay load
len = p->tot_len;
uint16_t bufferLength = 1500;
char buffer[bufferLength];
self->onReceive(pc);
self->receiveCallback(pc, buffer);
pbuf_free(p);
err = tcp_write(pcb, buffer, bufferLength, 0);
tcp_sent(pcb, data_sent);
}
if (err == ERR_OK && p == NULL) {
close_conn(pcb);
}
return ERR_OK;
}
示例2:
HTTPServerRequestDespatcher::HTTPServerRequestDespatcher(HTTPServer& httpServer, SQLiteDB* pMonitoringDB, SQLiteDB* pLoadTestingDB) :
m_server(httpServer),
m_pMonitoringDB(pMonitoringDB), m_pLoadTestingDB(pLoadTestingDB), m_pResultsSaver(NULL)
{
m_webContentPath = httpServer.getWebContentPath();
m_authenticationType = httpServer.getAuthenticationType();
}
示例3: run
void run()
{
#ifndef CINATRA_SINGLE_THREAD
HTTPServer s(num_threads_);
#else
HTTPServer s;
#endif
aop_.set_func(std::bind(&HTTPRouter::dispatch, router_, std::placeholders::_1, std::placeholders::_2, std::placeholders::_3));
s.set_request_handler([this](Request& req, Response& res)
{
ContextContainer ctx(app_container_);
return aop_.invoke(req, res, ctx);
})
.set_error_handler(error_handler_)
.static_dir(static_dir_);
for (auto const & info : http_listen_infos_)
{
s.listen(info.address, info.port);
}
#ifdef CINATRA_ENABLE_HTTPS
for (auto const & info : https_listen_infos_)
{
s.listen(info.address, info.port, info.cfg);
}
#endif // CINATRA_ENABLE_HTTPS
s.run();
}
示例4: read_cb
void read_cb(evutil_socket_t evs, short events, void *ptr) {
#ifdef _DEBUG_MODE_
printf("client %d: read_cb\n", evs);
//syslog(LOG_DEBUG, "client %d: read_cb\n", evs);
#endif
/* Last parameter is http server object */
HTTPServer *srv = (HTTPServer *)ptr;
/* Read from socket */
char buf[BUF_SIZE];
ssize_t len = recv(evs, buf, BUF_SIZE, 0);
if (len == 0) {
/* Close connection */
srv->finishReading(evs);
} else if (len != -1) {
/* Add string from inBuf */
std::string header(buf, len);
std::string inBuf = srv->getInBuf(evs);
if (!inBuf.empty())
header = inBuf + header;
/* Set response to client */
srv->setResponse(evs, header);
}
}
示例5: TestClient
//|//////////////////// TestClient //////////////////////////////////////////
void TestClient()
{
threadlib::ThreadControl tc;
HTTPServer server;
server.sigRespond.attach([&](HTTPServer::socket_t socket, HTTPRequest const &request) {
cout << " ServerReceive: " << request.method() << " " << request.location() << endl;
server.send(socket, HTTPResponse("<HTML>OK</HTML>"));
});
server.start(1202);
HTTPResponse response;
HTTPClient::execute(HTTPRequest("GET", "http://127.0.0.1:1202/objects"), &response);
// HTTPClient::execute(HTTPRequest("GET", "http://www.websocket.org/echo.html"), &response);
if (response.status() == 200)
{
cout << " ClientReceive: " << string(response.payload().begin(), response.payload().end()) << "\n";
}
else
cout << " ** No Data\n";
tc.join_threads();
cout << endl;
}
示例6: worker_cb
void worker_cb(evutil_socket_t evs, short events, void *ptr) {
int client_fd;
ssize_t size;
int BUF_LEN = 32;
char buf[BUF_LEN];
struct msghdr msg;
struct iovec iov;
union {
struct cmsghdr cmsghdr;
char control[CMSG_SPACE(sizeof(int))];
} cmsgu;
struct cmsghdr *cmsg;
iov.iov_base = (void *)buf;
iov.iov_len = BUF_LEN;
msg.msg_name = NULL;
msg.msg_namelen = 0;
msg.msg_iov = &iov;
msg.msg_iovlen = 1;
msg.msg_control = cmsgu.control;
msg.msg_controllen = sizeof(cmsgu.control);
size = recvmsg(evs, &msg, 0);
if (size < 0) {
perror("recvmsg");
exit(1);
}
cmsg = CMSG_FIRSTHDR(&msg);
if (cmsg && cmsg->cmsg_len == CMSG_LEN(sizeof(int))) {
if (cmsg->cmsg_level != SOL_SOCKET) {
fprintf(stderr, "invalid cmsg_level %d\n",
cmsg->cmsg_level);
exit(1);
}
if (cmsg->cmsg_type != SCM_RIGHTS) {
fprintf(stderr, "invalid cmsg_type %d\n",
cmsg->cmsg_type);
exit(1);
}
client_fd = *((int *)CMSG_DATA(cmsg));
printf("worker: received fd = %d\n", client_fd);
} else {
client_fd = -1;
}
if (client_fd != -1) {
/* Last parameter is http server object */
HTTPServer *srv = (HTTPServer *)ptr;
/* Add client to worker process */
srv->addWorkerClient(client_fd);
}
}
示例7: echo_accept
static err_t echo_accept(void *arg, struct tcp_pcb *pcb, err_t err)
{
HTTPServer* self = (HTTPServer*) arg;
self->onAccept();
tcp_setprio(pcb, TCP_PRIO_MIN);
tcp_recv(pcb, echo_recv);
tcp_err(pcb, NULL); //Don't care about error here
tcp_poll(pcb, NULL, 4); //No polling here
return ERR_OK;
}
示例8: main
int main() {
signal(SIGINT, sghandler);
signal(SIGPIPE, SIG_IGN);
SocketAddress a("127.0.0.1", 8000);
HTTPServer Server;
Server.Bind(a);
Server.Listen();
Server.Run();
return 0;
}
示例9: accept_cb
void accept_cb(evutil_socket_t evs, short events, void *ptr) {
#ifdef _DEBUG_MODE_
printf("server: accept_cb\n");
#endif
/* Last parameter is http server object */
HTTPServer *srv = (HTTPServer *)ptr;
/* Accept incoming connection */
int fd = accept(evs, 0, 0);
srv->addClient(fd);
}
示例10: LOG
//-----------------------------------------------------------------------------
void HTTPHandler::admin_handle(struct evhttp_request *req, void *arg) {
//TODO(binfei): need ssl and sepecial command to do admin privilege
LOG(INFO) << "Request for server admin.";
// TODO(binfei): need memory pool
struct evbuffer *databuf = evbuffer_new();
evbuffer_add_printf(databuf, "Server will be stoped.");
evhttp_send_reply_start(req, 200, "OK");
evhttp_send_reply_chunk(req, databuf);
evhttp_send_reply_end(req);
evbuffer_free(databuf);
HTTPServer *server = static_cast<HTTPServer*>(arg);
server->Stop();
}
示例11: main
int main(int argc, char *argv[]) {
std::cout << "Initializing HTTP server" << std::endl;
HTTPServer httpServer;
std::string featureServerAddr(argv[2]); // = "0.0.0.0:50051";
if (!httpServer.init(featureServerAddr)) {
qCritical() << "Starting HTTP Server failed";
return 1;
}
std::string httpServerAddr(argv[1]); // = "0.0.0.0:50056";
httpServer.run(httpServerAddr);
return 0;
}
示例12: main
int main(int argc, char** argv)
{
printf("Running CSL Version: %s\n", CSL::GetVersionString());
string configFile;
struct option longopts[] = {
{ "config", required_argument, NULL, 'f' },
{ 0, 0, 0, 0 }
};
int opt;
while ((opt = getopt_long(argc, argv, "f:", longopts, NULL)) != -1)
{
switch (opt) {
case 'f':
configFile = string(optarg);
break;
}
}
if (configFile.empty())
{
fprintf(stderr, "Error: Please specify a config file\n");
usage();
return 1;
}
Config config;
if (!config.Load(configFile))
{
fprintf(stderr, "Error: Failed to load config file %s\n", configFile.c_str());
return 1;
}
std::thread httpThread([&](){
HTTPServer* pServer = new HTTPServer(config);
pServer->Run();
delete pServer;
});
httpThread.join();
return 0;
}
示例13: write_cb
void write_cb(evutil_socket_t evs, short events, void *ptr) {
#ifdef _DEBUG_MODE_
printf("client %d: write_cb\n", evs);
#endif
/* Last parameter is http server object */
HTTPServer *srv = (HTTPServer *)ptr;
bool err_flag = false;
/* Answer with a string from outBuf */
std::string resp = srv->getResponse(evs);
assert(resp.size() > 0);
while (!resp.empty() && !err_flag) {
/* Send response */
ssize_t sent = send(evs, resp.c_str(), resp.size(), 0);
#ifdef _DEBUG_MODE_
printf("server: %zd/%zd bytes sent to client %d\n", sent, resp.size(), evs);
#endif
if (sent > 0) {
/* Decrease string size */
resp = resp.substr(sent);
} else {
err_flag = true;
}
}
if (err_flag) {
if (errno != EAGAIN) {
/* Remove write event for client */
srv->finishWriting(evs);
} else {
srv->pushToOutBuf(evs, resp);
}
} else {
std::string str = srv->getInBuf(evs);
if (str.empty()) {
/* Remove write event for client */
srv->finishWriting(evs);
} else {
srv->setResponse(evs, str);
}
}
}
示例14: HTTPServer
void DCServer::startServer ( )
{
HTTPServer *server = new HTTPServer();
server->start();
//Request * r = new Request("net_address_type");
//QJsonDocument data = r->get();
//parse("net_address_type", data);
/*r->setTablename("net_address");
data = r->get();
parse("net_address", data);*/
/*r->setTablename("device");
data = r->get();
parse("device", data);*/
//QObject::connect(taskMan, SIGNAL(sig_callTask(QString)), this, SLOT(slt_callDevice(QString)));
//taskMan->run();
}
示例15: main
// Our main test program
int
main(int argc,TCHAR* argv[], TCHAR* /*envp[]*/)
{
int nRetCode = 0;
HMODULE hModule = ::GetModuleHandle(NULL);
InitializeCriticalSection(&std_stream);
if(hModule == NULL)
{
_tprintf(_T("Fatal Error: GetModuleHandle failed\n"));
nRetCode = 1;
}
else
{
// initialize MFC and print and error on failure
if (!AfxWinInit(hModule, NULL, ::GetCommandLine(), 0))
{
_tprintf(_T("Fatal Error: MFC initialization failed\n"));
nRetCode = 1;
}
else
{
printf("TESTPROGAM: MARLIN SERVER\n");
printf("=========================\n");
printf("\n");
printf("Version string: %s\n",MARLIN_SERVER_VERSION);
printf("----------------------------------\n");
printf("\n");
// See if we must do the standalone WebServiceServer test
// Or that we should do the flat HTTPServer tests
if(argc >= 2)
{
if(_stricmp(argv[1],"/ws") == 0)
{
CString contract = "http://interface.marlin.org/testing/";
printf("WebServiceServer test for \"%s\"\n",contract.GetString());
printf("----------------------------------------------------------------\n");
printf("\n");
// Test the Interface
nRetCode = TestWebServiceServer(NULL,contract,logLevel);
}
}
else
{
HTTPServer* server = nullptr;
LogAnalysis* logfile = nullptr;
if(StartServer(server,logfile))
{
// Fire up all of our test sites
int errors = 0;
// Individual tests
errors += Test_CrackURL();
errors += Test_HTTPTime();
errors += TestThreadPool(server->GetThreadPool());
// HTTP tests
errors += TestBaseSite(server);
errors += TestSecureSite(server);
errors += TestClientCertificate(server,true);
errors += TestCookies(server);
errors += TestFormData(server);
errors += TestJsonData(server);
errors += TestInsecure(server);
errors += TestPushEvents(server);
errors += TestBodySigning(server);
errors += TestBodyEncryption(server);
errors += TestMessageEncryption(server);
errors += TestReliable(server);
errors += TestReliableBA(server);
errors += TestToken(server);
errors += TestSubSites(server);
errors += TestFilter(server);
errors += TestPatch(server);
errors += TestCompression(server);
errors += TestAsynchrone(server);
errors += TestWebSocket(server);
// Test the WebServiceServer program generation
CString contract = "http://interface.marlin.org/testing/";
errors += TestJsonServer(server,contract,logLevel);
errors += TestWebServiceServer(server,contract,logLevel);
// See if we should wait for testing to occur
if(errors)
{
printf("\n"
"SERVER (OR PROGRAMMING) IN ERROR STATE!!\n"
"%d sites not correctly started\n"
"\n",errors);
}
else
{
printf("\n"
"Server running....\n"
//.........这里部分代码省略.........