27 #include <sys/types.h>
32 # include <sys/ioctl.h>
35 #ifdef sun // ioctl(2)
38 # include <sys/filio.h>
52 #define BYTES_LEFT_IN_SOCKBUF(s) ((s).eof () ? -1 : (s).in_avail ())
59 #define BYTES_LEFT_IN_SIN (cin.eof () ? -1 : cin.rdbuf ()->in_avail ())
152 virtual bool open(
const int domain_) =0;
155 virtual bool close() =0;
175 virtual int write (
const char* buf_,
const u_int size_);
185 virtual int read (
char* buf_,
const u_int size_);
224 int ignore (
int n_ = INT_MAX,
int delim_ = EOF);
294 operator void* ()
const;
345 return (4 + s_.length () + s_.length () % 4);
396 return (*
this) << (char) c_;
402 return (*
this) << (char) c_;
451 closesocket (socket_);
470 int set_option (
int level_,
int optname_,
int val_);
523 m_nonblocking (false),
558 Socket::operator
void*()
const
560 return fail() ? (
void *)0 : (
void *)(-1);
static string decode_fcntl_flags(long mask_)
Decipher flags packed into mask_ used in fcntl() call.
void clear(iostate state_=Socket::goodbit)
Clear the socket state. Closed socket remains in bad state.
int m_type
Socket domain type.
virtual const int getDomain() const =0
Get socket domain.
IOState m_state
Control state of the socket.
virtual handler_t getHandler() const =0
Get file descriptor.
Socket & operator=(const Socket &)
bool fail() const
Indicates that earlier extraction opeartion has failed to match the required pattern of input...
bool operator!() const
Alias to fail()
void dumpState() const
Write state bits of the socket to the log file.
virtual bool open(const int domain_)=0
Open socket.
io_state_t
State bits: goodbit, eofbit, failbit, badbit.
virtual int write(const char *buf_, const u_int size_)
Write specified number of bytes to the socket.
int ignore(int n_=INT_MAX, int delim_=EOF)
Extracts bytes and discards them.
indicates that an input operation failed to read the expected characters, or that an output operation...
bool turnOptionOff(opt_t opt_)
Disable socket option.
static size_t xdr_length(const std::string &s_)
Give the true length of the XDR-encoded STL string.
#define BAD_HANDLER
Sort out WIN32/mingw oddities.
void disable_handler(handler_t &socket_)
Set socket descriptor to invalid value in a portable way.
indicates that socket is ready for use
virtual bool connect(const Address &address_)
Make a connection.
int getBytesAvail(void) const
Return number of bytes available in socket receive buffer.
bool is_valid_handler(handler_t socket_)
Detect socket() error in a portable way.
bool eof() const
An earlier extraction operation has encountered the end of file of the input stream (peer closed its ...
#define trace_with_mask(s, m)
trace_with_mask() is used to trace function call chain in C++ program.
bool setOption(opt_t opt_, int arg_)
Set socket option to value required.
int getOption(opt_t opt_) const
Get current value of a socket option.
iostate rdstate() const
Retrieve state of the socket.
virtual int in_avail() const =0
This function returns the number of characters immediately available in the get area of the underlyin...
virtual int read(char *buf_, const u_int size_)
Read expected number of bytes from the socket.
Socket & endl(Socket &os_)
endl manipulator.
int set_fd_options(long flags_)
Gateway method for setting file descriptor options.
Streambuf class is based on Standard C++ iostream streambuf class.
Set Socket to a non-blocking mode (O_RDWR|O_NONBLOCK).
int clear_fd_options(long flags_)
Gateway method for clearing file descriptor options.
Socket & ends(Socket &os_)
ends manipulator.
static const int PGSIZE
Size of bytes of a kernel page.
virtual Socket & flush()
This function simply calls the public "synchronizing" function rdbuf()->pubsync() (assuming the assoc...
Socket & operator>>(char &c)
Input of built-in char type. The value will be XDR-decoded.
Address is an abstraction for INET or UNIX-domain address data type.
virtual bool bind(const Address &my_address_)=0
Server binds listening socket to its local well-known port.
bool bad() const
Socket fd == -1 or read/write error occured or some loss of integrity on assosiated stream buffer...
virtual Streambuf * rdbuf()
Return a pointer to the Streambuf associated with the stream.
handler_t m_fd
File descriptor.
void setstate(iostate flag_)
Set socket state to flag_ by adding flag_ to the existing state.
Socket & operator<<(char c)
Output of built-in char type. The value will be XDR-encoded.
virtual Streambuf * rdbuf(Streambuf *)
Virtual function that sets new socket buffer and returns the old one.
bool good() const
Indicates no error on the socket.
static bool is_little_endian()
Determine the endianess of the platform we are on.
The receiver low-water mark is the amount of data that must be in the socket receive buffer for selec...
bool turnOptionOn(opt_t opt_)
Enable socket option.
Allow local address reuse.
virtual bool close()=0
Close socket.
The send low-water mark si the amount of available space that must exist in the socket send buffer fo...
int set_option(int level_, int optname_, int val_)
Gateway method of setting socket options.
virtual ~Socket()
Destructor.
indicates a loss of integrity in an input or output sequence (such as an irrecoverable read error fro...
indicates that an input operation reached the end of an input sequence
Socket & flush(Socket &os_)
flush manipulator.
static void close_handler(handler_t &socket_)
Close socket endpoint in a portable way.
Extended Socket & friends messages.