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