18#if defined (__FreeBSD__) || defined(__FreeBSD_kernel__) || defined (__CYGWIN32__) || defined (__GNU__)
19# include <sys/ioctl.h>
22#if defined (__NetBSD__)
23# include <sys/filio.h>
24# include <sys/ioctl.h>
28# define O_NONBLOCK 04000
66 ba +=
This->rdbuf ()->in_avail ();
132 DL ((
SOCKTRACE,
"Flags are set to %s via fcntl(25)\n",
176 DL ((
SOCKTRACE,
"Flags are set to %s via fcntl(%d)\n",
287#if defined (__CYGWIN32__) || defined (WIN32)
301 return (
ret == 0 ? 0 : 1);
312 register int count = 0;
324 if ( (
b =
read (&
c, 1)) == 0 ) {
393 while (
len-- &&
read (&
c, 1) == 1) {
405 if (
read ((
char*) &
val,
sizeof(
short)) ==
sizeof(
short)) {
436#define READ_INT(TYPE) \
437Socket& Socket::operator>>(TYPE& n_) \
440 int typesz = sizeof(TYPE);\
441 if (read ( (char* ) &val, typesz) == typesz) {\
442 if (sizeof(int32_t) <= typesz) {\
443 n_ = (TYPE) ntohl (val); \
446 if (Socket::is_little_endian ()) {\
447 *((int32_t*)(&n_)+1) = ntohl (*((int32_t*)(&val)) );\
448 *((int32_t*)(&n_) ) = ntohl (*((int32_t*)(&val))+1);\
451 *((int32_t*)(&n_) ) = ntohl (*((int32_t*)(&val)) );\
452 *((int32_t*)(&n_)+1) = ntohl (*((int32_t*)(&val))+1);\
457 setstate (Socket::eofbit|Socket::failbit);\
475 if (
read ((
char*) &
val,
sizeof(
float)) ==
sizeof(
float)) {
492 if (
read ((
char*) &
val,
sizeof(
double)) ==
sizeof(
double)) {
548 static const char pad [4] = { 0, 0, 0, 0 };
550 (*this) <<
s_.length ();
552 if (
ret !=
s_.length () ) {
555 size_t r = 4 -
s_.length() % 4;
569 if (
write ((
const char*) &
val,
sizeof(
short)) !=
sizeof(
short))
588#define WRITE_INT(TYPE) \
589Socket& Socket::operator<< (TYPE n_) \
592 int typesz = sizeof(TYPE);\
593 if (sizeof(int32_t) <= typesz) {\
594 val = (TYPE) ntohl (n_); \
597 if (Socket::is_little_endian ()) {\
598 *((int32_t*)(&val)+1) = htonl (*((int32_t*)(&n_)) );\
599 *((int32_t*)(&val) ) = htonl (*((int32_t*)(&n_))+1);\
602 *((int32_t*)(&val) ) = htonl (*((int32_t*)(&n_)) );\
603 *((int32_t*)(&val)+1) = htonl (*((int32_t*)(&n_))+1);\
606 if (write ((const char*) &val, typesz) != typesz) {\
607 setstate (Socket::eofbit|Socket::failbit);\
626 int ret =
write ((
const char*) &
buf,
sizeof(
float));
628 if (
ret !=
sizeof(
float) ) {
643 int ret =
write ((
const char*) &
buf,
sizeof(
double));
645 if (
ret !=
sizeof(
double) ) {
660 std::ostringstream
msg;
663 msg <<
"\tTesting good() ....... ";
668 msg <<
"\tTesting eof() ........ ";
672 msg <<
"\tTesting fail() ....... ";
676 msg <<
"\tTesting bad() ........ ";
680 msg <<
"\tTesting !() .......... ";
684 msg <<
"\tTesting void *() ..... ";
688 msg <<
"\tTesting nonblocking... ";
#define EL(X)
A macro for writing error message to the Logger.
#define DL(X)
A macro for writing debug message to the Logger.
#define trace_with_mask(s, m)
trace_with_mask() is used to trace function call chain in C++ program.
Abstraction of socket data type.
XDRHack provides XDR definitions for systems that have them missing.
A wrapper class to provide AutoPtr with reference semantics.
bool fail() const
Indicates that earlier extraction opeartion has failed to match the required pattern of input.
int clear_fd_options(long flags_)
Gateway method for clearing file descriptor options.
Socket & operator>>(char &c)
Input of built-in char type. The value will be XDR-decoded.
virtual Streambuf * rdbuf()
Return a pointer to the Streambuf associated with the stream.
void dumpState() const
Write state bits of the socket to the log file.
void setstate(iostate flag_)
Set socket state to flag_ by adding flag_ to the existing state.
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.
bool turnOptionOff(opt_t opt_)
Disable socket option.
virtual int read(char *buf_, const u_int size_)
Read expected number of bytes from the socket.
int set_option(int level_, int optname_, int val_)
Gateway method of setting socket options.
bool turnOptionOn(opt_t opt_)
Enable socket option.
@ 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...
@ rcvlowat
The receiver low-water mark is the amount of data that must be in the socket receive buffer for selec...
@ nonblocking
Set Socket to a non-blocking mode (O_RDWR|O_NONBLOCK).
static bool is_little_endian()
Determine the endianess of the platform we are on.
bool eof() const
An earlier extraction operation has encountered the end of file of the input stream (peer closed its ...
handler_t m_fd
File descriptor.
bool bad() const
Socket fd == -1 or read/write error occured or some loss of integrity on assosiated stream buffer.
int getOption(opt_t opt_) const
Get current value of a socket option.
bool good() const
Indicates no error on the 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.
virtual Socket & flush()
This function simply calls the public "synchronizing" function rdbuf()->pubsync() (assuming the assoc...
@ eofbit
indicates that an input operation reached the end of an input sequence
@ badbit
indicates a loss of integrity in an input or output sequence (such as an irrecoverable read error fro...
@ failbit
indicates that an input operation failed to read the expected characters, or that an output operation...
static const int PGSIZE
Size of bytes of a kernel page.
bool setOption(opt_t opt_, int arg_)
Set socket option to value required.
virtual int write(const char *buf_, const u_int size_)
Write specified number of bytes to the socket.
int getBytesAvail(void) const
Return number of bytes available in socket receive buffer.
@ SOCKTRACE
Extended Socket & friends messages
@ ASSAERR
ASSA and system errors