#ifndef __pxx_stream_socket_ih__ #define __pxx_stream_socket_ih__ #include "pxx_stream_socket.hh" #include "pxx_sock_addr.ih" #include "pxx_sys_error.ih" #include #include #include namespace pxx { inline StreamSocket::StreamSocket ( address_family_t _af, uint16_t _port /* = 0 */ ) : local_addr (_af, _port), remote_addr (null) { fd = socket(_af, SOCK_STREAM, IPPROTO_TCP); if (fd == -1) throw_sys_error(errno); if (bind(fd, local_addr.addr, local_addr.addrlen) != 0) throw_sys_error(errno); } inline StreamSocket::~StreamSocket () { if (remote_addr != null) delete remote_addr; } inline void StreamSocket::connect (char const* _host, uint16_t _port) { remote_addr = new SockAddr(_host, _port); if (::connect(fd, remote_addr->addr, remote_addr->addrlen) != 0) throw_sys_error(errno); } inline int StreamSocket::get_fd () const { return fd; } } #endif // __pxx_stream_socket_ih__