Pol  Revision:cb584c9
socketsvc.cpp
Go to the documentation of this file.
1 
7 #include <stdlib.h>
8 
9 #include "logfacility.h"
10 #include "socketsvc.h"
11 #include "strutil.h"
12 #include "threadhelp.h"
13 
14 namespace Pol
15 {
16 namespace Clib
17 {
18 SocketListener::SocketListener( unsigned short port ) : _listen_sck()
19 {
20  if ( !_listen_sck.listen( port ) )
21  {
22  POLLOG_ERROR << "Unable to open listen port " + decint( port );
23  abort();
24  }
25 }
26 
28 {
29  _listen_sck.set_options( opt );
30 
31  if ( !_listen_sck.listen( port ) )
32  {
33  POLLOG_ERROR << "Unable to open listen port " + decint( port );
34  abort();
35  }
36 }
37 
38 bool SocketListener::GetConnection( unsigned int timeout_sec )
39 {
40  return _listen_sck.select( timeout_sec, 0 );
41 }
42 
44 {
45  _listen_sck.accept( newsck ); // FIXME return ignored
46 }
47 
48 
50 {
51  SL.accept( _sck );
52 }
54 
55 static void _thread_stub2( void* arg )
56 {
57  std::unique_ptr<SocketClientThread> sct( static_cast<SocketClientThread*>( arg ) );
58  sct->run();
59 }
60 
62 {
63  threadhelp::start_thread( _thread_stub2, "SocketClientThread", this );
64 }
65 
67 {
68  threadhelp::start_thread( _thread_stub2, "SocketClientThread", instance );
69 }
70 }
71 }
SocketClientThread(SocketListener &SL)
Definition: socketsvc.cpp:49
static void start_thread(SocketClientThread *instance)
Definition: socketsvc.cpp:66
std::string decint(unsigned short v)
Definition: strutil.cpp:64
bool listen(unsigned short port)
Definition: wnsckt.cpp:216
void start_thread(void(*entry)(void *), const char *thread_name, void *arg)
Definition: threadhelp.cpp:233
#define POLLOG_ERROR
Definition: logfacility.h:207
void accept(Socket &newsck)
Definition: socketsvc.cpp:43
bool accept(SOCKET *s, unsigned int mstimeout)
Definition: wnsckt.cpp:275
SocketListener(unsigned short port)
Definition: socketsvc.cpp:18
static void _thread_stub2(void *arg)
Definition: socketsvc.cpp:55
bool select(unsigned int seconds, unsigned int useconds)
Definition: wnsckt.cpp:250
bool GetConnection(unsigned int timeout_sec)
Definition: socketsvc.cpp:38
void set_options(option opt)
Definition: wnsckt.cpp:82
Definition: berror.cpp:12