51 #define SOCK_NONBLOCK O_NONBLOCK 73 const char* bindport,
int proto_osi3,
75 setup(bindhost, bindport, proto_osi3, flags);
89 const string& bindport,
int proto_osi3,
91 setup(bindhost, bindport, proto_osi3, flags);
106 int proto_osi3,
int flags) {
109 "inet_stream_server::inet_stream_server() - " 110 "already bound and listening!",
112 if (bindhost == 0 || bindport == 0)
114 "inet_stream_server::inet_stream_server() - at " 115 "least one bind argument invalid!",
118 bindhost, bindport, LIBSOCKET_TCP, proto_osi3, flags)))
120 "inet_stream_server::inet_stream_server() - " 121 "could not create server socket!");
123 host = string(bindhost);
124 port = string(bindport);
126 is_nonblocking = flags & SOCK_NONBLOCK;
141 int proto_osi3,
int flags) {
144 "inet_stream_server::inet_stream_server() - " 145 "already bound and listening!",
147 if (bindhost.empty() || bindport.empty())
149 "inet_stream_server::inet_stream_server() - at " 150 "least one bind argument invalid!",
154 LIBSOCKET_TCP, proto_osi3, flags)))
156 "inet_stream_server::inet_stream_server() - " 157 "could not create server socket!");
159 host = string(bindhost);
160 port = string(bindport);
162 is_nonblocking = flags & SOCK_NONBLOCK;
178 return accept2(numeric, accept_flags).release();
197 "inet_stream_server::accept() - stream server socket is not in " 198 "listening state -- please call first setup()!");
200 using std::unique_ptr;
201 unique_ptr<char[]> src_host(
new char[1024]);
202 unique_ptr<char[]> src_port(
new char[32]);
204 memset(src_host.get(), 0, 1024);
205 memset(src_port.get(), 0, 32);
212 numeric, accept_flags))) {
213 if (!is_nonblocking && errno != EWOULDBLOCK) {
216 "inet_stream_server::accept() - could not accept new " 217 "connection on stream server socket!");
224 client->sfd = client_sfd;
226 string(src_host.get());
229 client->port = string(src_port.get());
230 client->proto =
proto;
235 const string& inet_stream_server::getbindhost(
void) {
return gethost(); }
237 const string& inet_stream_server::getbindport(
void) {
return getport(); }
Contains libsocket elements.
unique_ptr< inet_stream > accept2(int numeric=0, int accept_flags=0)
Accept a connection and return a socket connected to the client.
int create_inet_server_socket(const char *bind_addr, const char *bind_port, char proto_osi4, char proto_osi3, int flags)
Create a TCP or UDP server socket.
This class is instantiated and thrown when an error occurs. If there's an error somewhere in libsocke...
Provides TCP/IP client sockets. This class is the most used socket class in libsocket++....
void setup(const char *bindhost, const char *bindport, int proto_osi3, int flags=0)
Set up a server socket.
const string & getport(void) const
inet_stream * accept(int numeric=0, int accept_flags=0)
Accept a connection and return a socket connected to the client.
int accept_inet_stream_socket(int sfd, char *src_host, size_t src_host_len, char *src_service, size_t src_service_len, int flags, int accept_flags)
Accept a connection attempt on a server socket.
inet_stream_server(void)
Void constructor; don't forget to setup() the socket before use!
string port
The port we're bound or connected to.
int sfd
sfd is the sockets API file descriptor
int proto
Which internet protocol version we're using.
const string & gethost(void) const
string host
The address we're bound or connected to.
Contains all functions available in the C libsocket.