Menu

[94f52a]: / poll / socket_client.hpp  Maximize  Restore  History

Download this file

42 lines (31 with data), 903 Bytes

 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
#ifndef CHILON_POLL_SOCKET_CLIENT_HPP
#define CHILON_POLL_SOCKET_CLIENT_HPP
#include <chilon/poll/pollable.hpp>
#include <sys/types.h>
#include <sys/socket.h>
#include <arpa/inet.h>
#include <fcntl.h>
#include <exception>
namespace chilon { namespace poll {
struct could_not_create_socket : std::exception {};
/**
* @brief socket_client represents a stream for a single socket based client
*/
template <class Client>
struct socket_client : public pollable {
void tcp_create() {
fd_ = ::socket(PF_INET, SOCK_STREAM, 0);
fcntl(fd_, F_SETFL, O_NONBLOCK);
if (-1 == fd_) throw could_not_create_socket();
}
void tcp_close() {
shutdown(fd_, SHUT_RDWR);
fd_ = -1;
}
bool closed() const { return -1 == fd_; }
int fd() const { return fd_; }
socket_client() {}
socket_client(int const socket) : pollable(socket) {}
};
} }
#endif
Want the latest updates on software, tech news, and AI?
Get latest updates about software, tech news, and AI from SourceForge directly in your inbox once a month.