-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmain.cpp
47 lines (44 loc) · 1.35 KB
/
main.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
#include <streambuf>
#include <iostream>
#include <sstream>
#include "boost/filesystem/path.hpp"
#include <myserversocket.h>
#include <algorithm>
#include <vector>
#include "client.h"
#include "logger.h"
#include "parser_arg.h"
int main(int argc, char *argv[])
{
parser_arg flags(argc,argv);
boost::filesystem::path pt(flags.get_work_dir());
Logger::InitLog(std::string("mylogfile"));
Logger& logs = Logger::Instance();
logs.Log("Starting server");
MyServerSocket sock;
sock.mbind(flags.get_port());
sock.mlisten();
std::vector<Client*> clients;
while (1) {
usleep(100);
while(std::shared_ptr<MyServerSocket> client = sock.maccept())
{
client->setNonBlocked(1);
Client* buf = new Client(client,pt);
clients.push_back(buf);
}
for(std::vector<Client*>::iterator i = clients.begin(); i < clients.end(); i++) {
if(((*i)->hasCmd())&&(!(*i)->finish())) {
(*i)->execCmd();
}
}
for(std::vector<Client*>::iterator i = clients.begin(); i < clients.end(); i++) {
if((*i)->finish()) {
Client* buf = *i;
clients.erase(i);
delete buf;
}
}
}
return 0;
}