26 # define _CRT_SECURE_NO_DEPRECATE // vs8
27 # pragma warning (disable: 4251) // STL MAP DLL warning noise (JW)
30 #include "CScommServer.hh"
36 # include <sys/poll.h>
37 # include <netinet/in.h>
38 # include <sys/socket.h>
41 # include <netinet/tcp.h>
44 #include <Base/Debug/Error.hh>
45 #include <sys/types.h>
54 CScommServer::CScommServer(
bool threaded) :
CScommBase(threaded)
75 BIASDOUT(D_CS_LISTENER,mygetpid() <<
": Starting listener on port " <<
80 BIASERR(
"cant crete listen thread");
92 struct sockaddr_in client_addr;
100 int listenfd, newclientfd;
106 listenfd=(int)socket (AF_INET, SOCK_STREAM, 0);
117 memset(&client_addr, 0,
sizeof(client_addr));
118 client_addr.sin_family = AF_INET;
119 client_addr.sin_addr.s_addr = INADDR_ANY;
122 bool * flag =
new bool(
true);
123 int length =
sizeof(bool);
124 setsockopt(listenfd, IPPROTO_TCP, TCP_NODELAY, (
char *) flag, length);
131 while ((res<0) && tries<maxTries) {
132 client_addr.sin_port = htons((u_short) comm->
connectPort_);
134 res = ::bind(listenfd,(
struct sockaddr *) &client_addr,
135 sizeof(client_addr));
138 cout<<
"res<0"<<
" Erorr:'"<<strerror(errno)<<endl;
143 if ( (res<0) && (tries>maxTries) ) {
144 BIASERR(
"Erorr:'"<<strerror(errno)<<
"' for ports:"
155 res = listen(listenfd,1);
157 perror(
"Listening for clients");
165 clilen =
sizeof(client_addr);
166 newclientfd = (int)accept(listenfd,(
struct sockaddr *)&client_addr,&clilen);
169 cout << mygetpid() <<
": Listener got something"<<endl;
172 perror(
"Error accepting connection from client");
178 closesocket(newclientfd);
187 cout <<
"Client accepted, relistening"<<endl;
void CreateListenThread_()
void * listenthread(void *data)
these are wrapper to comply to the pthread_create() interface
void WaitForConnections(unsigned int port=D_CS_DEFAULT_PORT)
Init function, returns instantly and enables the server to accept connections on the given port ...
int GetDebugLevel() const
class for sending/receiving data between clients and serversOnly registered msgs will be accepted at ...
this class CScomm (ClientServer communciation) handles data comunication via TCP/IP for one server an...
pthread_t pthreadListener_
friend void * listenthread(void *data)
these are wrapper to comply to the pthread_create() interface