Jpp 19.3.0-rc.1
the software that should make you happy
Loading...
Searching...
No Matches
JServerSocket.hh
Go to the documentation of this file.
1#ifndef __JNET__JSERVERSOCKET__
2#define __JNET__JSERVERSOCKET__
3
4#include <sys/select.h>
5#include <limits>
6
7#include "JLang/JException.hh"
8#include "JNet/JTCPSocket.hh"
9
10
11/**
12 * \author mdejong
13 */
14
15namespace JNET {}
16namespace JPP { using namespace JNET; }
17
18namespace JNET {
19
22
23
24 /**
25 * TCP server socket.
26 */
28 public JTCPSocket
29 {
30 public:
31 /**
32 * Constructor.
33 *
34 * \param port port number
35 * \param backlog backlog
36 */
37 JServerSocket(const int port,
38 const int backlog)
39 {
40 setReuseAddress(true);
41 setTcpNoDelay (true);
43 setPort(port);
44
45 if (::bind(getFileDescriptor(), getSockaddr(), sizeof(sockaddr)) < 0) {
46 THROW(JSocketException, "Bind socket failed " << errno);
47 }
48
49 if (::listen(getFileDescriptor(), backlog) < 0) {
50 THROW(JSocketException, "Listen socket failed " << errno);
51 }
52 }
53 };
54}
55
56#endif
Exceptions.
#define THROW(JException_t, A)
Marco for throwing exception with std::ostream compatible message.
int getFileDescriptor() const
Get file descriptor.
Auxiliary class for method select.
Exception for socket.
TCP server socket.
JServerSocket(const int port, const int backlog)
Constructor.
const sockaddr * getSockaddr() const
Get sockaddr.
void setIPnumber()
Set any IP number.
void setPort(const int port)
Set port number.
void setReuseAddress(const bool on)
Set reuse address.
Definition JSocket.hh:126
TCP socket.
Definition JTCPSocket.hh:30
void setTcpNoDelay(const bool on)
Set TCP no-delay.
This name space includes all other name spaces (except KM3NETDAQ, KM3NET and ANTARES).