#include <Socket.h>
Inheritance diagram for ASSA::Socket:
Public Types | |
typedef int | iostate |
typedef unsigned char | IOState |
enum | io_state_t { goodbit = 0, eofbit = 1, failbit = 2, badbit = 4 } |
State bits: goodbit, eofbit, failbit, badbit. More... | |
enum | opt_t { reuseaddr, rcvlowat, sndlowat, blocking, nonblocking } |
Socket options. More... | |
Public Member Functions | |
Socket () | |
Constructor. | |
virtual | ~Socket () |
Destructor. | |
virtual bool | open (const int domain_)=0 |
Open socket. | |
virtual bool | close ()=0 |
Close socket. | |
virtual bool | connect (const Address &address_) |
Make a connection. | |
virtual bool | bind (const Address &my_address_)=0 |
Server binds listening socket to its local well-known port. | |
virtual int | write (const char *buf_, const unsigned int size_) |
Write specified number of bytes to the socket. | |
int | getBytesAvail (void) const |
Return number of bytes available in socket receive buffer. | |
virtual int | read (char *buf_, const unsigned int size_) |
Read expected number of bytes from the socket. | |
int | ignore (int n_=INT_MAX, int delim_=EOF) |
Extracts bytes and discards them. | |
virtual const int | getHandler () const =0 |
Get file descriptor. | |
virtual const int | getDomain () const =0 |
Get socket domain. | |
virtual Streambuf * | rdbuf () |
Return a pointer to the Streambuf associated with the stream. | |
virtual Streambuf * | rdbuf (Streambuf *) |
Virtual function that sets new socket buffer and returns the old one. | |
virtual int | in_avail () const =0 |
This function returns the number of characters immediately available in the get area of the underlying Socketbuf buffer without making a system call if Socket is doing buffering I/O. | |
virtual Socket & | flush () |
This function simply calls the public "synchronizing" function rdbuf()->pubsync() (assuming the associated streambuf object is present). | |
bool | turnOptionOn (opt_t opt_) |
Enable socket option. | |
bool | turnOptionOff (opt_t opt_) |
Disable socket option. | |
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. | |
operator void * () const | |
Convertion to void* (for testing where bool is required). | |
bool | operator! () const |
Alias to fail(). | |
iostate | rdstate () const |
Retrieve state of the socket. | |
void | clear (iostate state_=Socket::goodbit) |
Clear the socket state. Closed socket remains in bad state. | |
void | setstate (iostate flag_) |
Set socket state to flag_ by adding flag_ to the existing state. | |
bool | good () const |
Indicates no error on the socket. | |
bool | eof () const |
An earlier extraction operation has encountered the end of file of the input stream (peer closed its socket). | |
bool | fail () const |
Indicates that earlier extraction opeartion has failed to match the required pattern of input. | |
bool | bad () const |
Socket fd == -1 or read/write error occured or some loss of integrity on assosiated stream buffer. | |
void | dumpState () const |
Write state bits of the socket to the log file. | |
Socket & | operator>> (char &c) |
Input of built-in char type. The value will be XDR-decoded. | |
Socket & | operator>> (unsigned char &c_) |
Input of built-in u_char type. The value will be XDR-decoded. | |
Socket & | operator>> (signed char &c_) |
Input of built-in signed char type. The value will be XDR-decoded. | |
Socket & | operator>> (std::string &s_) |
Input of STL string type. The string content will be XDR-decoded. | |
Socket & | operator>> (short &n_) |
Input of built-in short type. The value will be XDR-decoded. | |
Socket & | operator>> (unsigned short &n_) |
Input of built-in u_short type. The value will be XDR-decoded. | |
Socket & | operator>> (int &n_) |
Input of built-in integer type. The value will be XDR-decoded. | |
Socket & | operator>> (unsigned int &n_) |
Input of built-in u_int type. The value will be XDR-decoded. | |
Socket & | operator>> (long &n_) |
Input of built-in long type. The value will be XDR-decoded. | |
Socket & | operator>> (unsigned long &n_) |
Input of built-in u_long type. The value will be XDR-decoded. | |
Socket & | operator>> (float &n_) |
Input of built-in float type. The value will be XDR-decoded. | |
Socket & | operator>> (double &n_) |
Input of built-in double type. The value will be XDR-decoded. | |
Socket & | operator<< (char c) |
Output of built-in char type. The value will be XDR-encoded. | |
Socket & | operator<< (unsigned char c_) |
Output of built-in u_char type. The value will be XDR-encoded. | |
Socket & | operator<< (signed char c_) |
Output of built-in signed char type. The value will be XDR-encoded. | |
Socket & | operator<< (const std::string &s_) |
Output of STL string type. The value will be XDR-encoded. | |
Socket & | operator<< (short n_) |
Output of built-in short type. The value will be XDR-encoded. | |
Socket & | operator<< (unsigned short n_) |
Output of built-in u_short type. The value will be XDR-encoded. | |
Socket & | operator<< (int n_) |
Output of built-in integer type. The value will be XDR-encoded. | |
Socket & | operator<< (unsigned int n_) |
Output of built-in u_int type. The value will be XDR-encoded. | |
Socket & | operator<< (long n_) |
Output of built-in long type. The value will be XDR-encoded. | |
Socket & | operator<< (unsigned long n_) |
Output of built-in u_long type. The value will be XDR-encoded. | |
Socket & | operator<< (float n_) |
Output of built-in float type. The value will be XDR-encoded. | |
Socket & | operator<< (double n_) |
Output of built-in double type. The value will be XDR-encoded. | |
Socket & | operator<< (Socket &(*f)(Socket &)) |
Manipulators plug-in operator. | |
Static Public Member Functions | |
static size_t | xdr_length (const std::string &s_) |
Give the true length of the XDR-encoded STL string. | |
static bool | is_little_endian () |
Determine the endianess of the platform we are on. | |
Static Public Attributes | |
static const int | PGSIZE = 4096 |
Size of bytes of a kernel page. | |
Protected Member Functions | |
int | set_option (int level_, int optname_, int val_) |
Gateway method of setting socket options. | |
int | set_fd_options (int flags_) |
Gateway method for setting file descriptor options. | |
int | clear_fd_options (int flags_) |
Gateway method for clearing file descriptor options. | |
Protected Attributes | |
int | m_fd |
File descriptor. | |
int | m_type |
Socket domain type. | |
IOState | m_state |
Control state of the socket. | |
Private Member Functions | |
Socket (const Socket &) | |
The copy constructor and assignment operator are private to prevent copying of Socket objects, since the effect of such copying is not well defined. | |
Socket & | operator= (const Socket &) |
Definition at line 70 of file Socket.h.
|
|
|
|
|
State bits: goodbit, eofbit, failbit, badbit. Meaning to these is explained in class' documentation.
Definition at line 79 of file Socket.h.
|
|
Socket options.
Definition at line 97 of file Socket.h. 00097 { 00098 reuseaddr, 00099 rcvlowat, 00104 sndlowat, 00110 blocking, 00120 nonblocking 00134 };
|
|
Constructor.
Definition at line 481 of file Socket.h. References ASSA::SOCKTRACE, and trace_with_mask. 00482 : m_fd(-1), m_type(0), m_state(Socket::badbit) 00483 { 00484 trace_with_mask("Socket::Socket",SOCKTRACE); 00485 }
|
|
Destructor.
Definition at line 488 of file Socket.h. References ASSA::SOCKTRACE, and trace_with_mask. 00489 { 00490 trace_with_mask("Socket::~Socket",SOCKTRACE); 00491 }
|
|
The copy constructor and assignment operator are private to prevent copying of Socket objects, since the effect of such copying is not well defined. Usually you want to copy a pointer to the object, or pass a reference to a function. |
|
Socket fd == -1 or read/write error occured or some loss of integrity on assosiated stream buffer.
Definition at line 328 of file Socket.h. References badbit, and m_state. 00328 { return m_state & Socket::badbit; }
|
|
Server binds listening socket to its local well-known port.
Implemented in ASSA::IPv4Socket, and ASSA::UDPSocket. |
|
Clear the socket state. Closed socket remains in bad state.
Definition at line 528 of file Socket.h. References badbit, m_fd, and m_state. Referenced by ASSA::IPv4Socket::accept(), and ASSA::IPv4Socket::clone(). 00529 { 00530 m_state = m_fd >=0 ? state_ : state_ | Socket::badbit; 00531 }
|
|
Gateway method for clearing file descriptor options.
Definition at line 94 of file Socket.cpp. References m_fd. Referenced by setOption(), turnOptionOff(), and turnOptionOn(). 00095 { 00096 int val; 00097 if ((val = fcntl (m_fd, F_GETFL, 0)) < 0) { 00098 return -1; 00099 } 00100 val &= ~flags_; // turn flags off 00101 00102 return (fcntl (m_fd, F_SETFL, val) < 0) ? -1 : 0; 00103 }
|
|
Close socket.
Implemented in ASSA::IPv4Socket, and ASSA::UDPSocket. |
|
Make a connection.
Reimplemented in ASSA::ConUDPSocket, and ASSA::IPv4Socket. Definition at line 494 of file Socket.h. References ASSA::SOCKTRACE, and trace_with_mask. 00495 { 00496 trace_with_mask("Socket::connect",SOCKTRACE); 00497 return false; 00498 }
|
|
Write state bits of the socket to the log file.
Definition at line 578 of file Socket.cpp. References DL, ASSA::ends(), getOption(), nonblocking, ASSA::SOCKTRACE, and trace_with_mask. 00579 { 00580 trace_with_mask("Socket::dumpState",SOCKTRACE); 00581 00582 char state_set[] = "[ set]\n"; 00583 char state_not_set[] = "[not set]\n"; 00584 00585 std::ostringstream msg; 00586 00587 msg << "\n"; 00588 msg << "\tTesting good() ....... "; 00589 00590 if (this->good ()) msg << state_set; 00591 else msg << state_not_set; 00592 00593 msg << "\tTesting eof() ........ "; 00594 if (this->eof ()) msg << state_set; 00595 else msg << state_not_set; 00596 00597 msg << "\tTesting fail() ....... "; 00598 if (this->fail ()) msg << state_set; 00599 else msg << state_not_set; 00600 00601 msg << "\tTesting bad() ........ "; 00602 if (this->bad ()) msg << state_set; 00603 else msg << state_not_set; 00604 00605 msg << "\tTesting !() .......... "; 00606 if ( !(*this) ) msg << state_set; 00607 else msg << state_not_set; 00608 00609 msg << "\tTesting void *() ..... "; 00610 if ( *this ) msg << state_set; 00611 else msg << state_not_set; 00612 00613 msg << "\tTesting nonblocking... "; 00614 if (getOption (nonblocking) == 1) msg << state_set; 00615 else msg << state_not_set; 00616 00617 /*--- Terminate stream buffer ---*/ 00618 msg << std::ends; 00619 00620 DL((SOCKTRACE,"%s\n", msg.str ().c_str ())); 00621 }
|
|
An earlier extraction operation has encountered the end of file of the input stream (peer closed its socket).
Definition at line 312 of file Socket.h. References eofbit, and m_state. 00312 { return m_state & Socket::eofbit; }
|
|
Indicates that earlier extraction opeartion has failed to match the required pattern of input. Socket should be closed at this point by the owner.
Definition at line 319 of file Socket.h. References badbit, failbit, and m_state. Referenced by operator void *(), and operator!(). 00320 { 00321 return m_state & (Socket::failbit | Socket::badbit); 00322 }
|
|
This function simply calls the public "synchronizing" function rdbuf()->pubsync() (assuming the associated streambuf object is present). Typically, such an operation flushes an output stream to the associated external pipe. Definition at line 58 of file Socket.cpp. References badbit, good(), rdbuf(), and setstate(). Referenced by ASSA::IPv4Socket::close(), ASSA::endl(), and ASSA::flush(). 00059 { 00060 if (good () && rdbuf ()) { 00061 if (rdbuf ()->pubsync () == EOF) { 00062 setstate (badbit); 00063 } 00064 } 00065 return (*this); 00066 }
|
|
Return number of bytes available in socket receive buffer. Sum of these two numbers is the true number of bytes available for immediate reading. Definition at line 38 of file Socket.cpp. References DL, EL, ASSA::ERROR, ASSA::Streambuf::in_avail(), m_fd, rdbuf(), ASSA::SOCKTRACE, and trace_with_mask. Referenced by ASSA::operator>>(), and ASSA::Socketbuf::showmanyc(). 00039 { 00040 trace_with_mask("Socket::getBytesAvail",SOCKTRACE); 00041 00042 Socket* This = (Socket*) this; 00043 int ba = 0; 00044 int ret = ioctl (m_fd, FIONREAD, &ba); 00045 00046 if (ret == -1) { 00047 EL((ERROR,"ioctl(2) failed with ret: %d\n", ret)); 00048 return ret; 00049 } 00050 ba += This->rdbuf ()->in_avail (); 00051 00052 DL((SOCKTRACE,"%d bytes available for reading\n", ba)); 00053 return ba; 00054 }
|
|
Get socket domain.
Implemented in ASSA::IPv4Socket, and ASSA::UDPSocket. |
|
Get file descriptor.
Implemented in ASSA::IPv4Socket, and ASSA::UDPSocket. Referenced by ASSA::Socketbuf::sys_read(), and ASSA::Socketbuf::sys_write(). |
|
Get current value of a socket option.
Definition at line 175 of file Socket.cpp. References blocking, EL, ASSA::ERROR, m_fd, nonblocking, rcvlowat, reuseaddr, sndlowat, ASSA::SOCKTRACE, and trace_with_mask. Referenced by dumpState(). 00176 { 00177 trace_with_mask("Socket::getOption",SOCKTRACE); 00178 int optval = 0; 00179 00180 if (nonblocking == opt_) { 00181 if ((optval = fcntl (m_fd, F_GETFL, 0)) < 0) { 00182 return -1; 00183 } 00184 return ((optval & O_NONBLOCK) == O_NONBLOCK ? 1 : 0); 00185 } 00186 00187 if (blocking == opt_) { 00188 if ((optval = fcntl (m_fd, F_GETFL, 0)) < 0) { 00189 return -1; 00190 } 00191 return ((optval & O_NONBLOCK) == O_NONBLOCK ? 0 : 1); 00192 } 00193 00194 int optname; 00195 int level = SOL_SOCKET; 00196 bool bin = false; 00197 00198 socklen_t len = sizeof (optval); 00199 int ret; 00200 00201 if (rcvlowat == opt_) { 00202 optname = SO_RCVLOWAT; 00203 } 00204 else if (sndlowat == opt_) { 00205 optname = SO_SNDLOWAT; 00206 } 00207 else if (reuseaddr == opt_) { 00208 optname = SO_REUSEADDR; 00209 bin = true; 00210 } 00211 else { 00212 EL((ERROR,"Invalid socket option\n")); 00213 return (-1); 00214 } 00215 00216 #ifndef __CYGWIN32__ 00217 ret = getsockopt (m_fd, level, optname, (char*) &optval, &len); 00218 #else 00219 ret = getsockopt (m_fd, level, optname, (char*) &optval, (int*)&len); 00220 #endif 00221 00222 if (ret < 0) { 00223 return (-1); 00224 } 00225 if (bin) { 00226 return (ret == 0 ? 0 : 1); 00227 } 00228 return (ret); 00229 }
|
|
Indicates no error on the socket.
Definition at line 306 of file Socket.h. References m_state. Referenced by ASSA::IPv4Socket::clone(), and flush(). 00306 { return m_state == 0; }
|
|
Extracts bytes and discards them. With no arguments, read and discard until eof is encountered. Bytes are extracted in the following manner:
Definition at line 233 of file Socket.cpp. References eofbit, failbit, PGSIZE, read(), setstate(), ASSA::SOCKTRACE, and trace_with_mask. Referenced by operator>>(). 00234 { 00235 trace_with_mask("Socket::ignore",SOCKTRACE); 00236 register int b; 00237 register int count = 0; 00238 register char c; 00239 00240 if (n_ == INT_MAX && delim_ == EOF) { 00241 char buf[PGSIZE]; 00242 while ((b = read (buf, PGSIZE))) { 00243 count += b; 00244 } 00245 setstate (Socket::eofbit|Socket::failbit); 00246 return count; 00247 } 00248 for (; n_; n_--, count++) { 00249 if ( (b = read (&c, 1)) == 0 ) { 00250 setstate (Socket::eofbit|Socket::failbit); 00251 break; 00252 } 00253 if ( c == delim_ ) 00254 break; 00255 } 00256 return count; 00257 }
|
|
This function returns the number of characters immediately available in the get area of the underlying Socketbuf buffer without making a system call if Socket is doing buffering I/O. It is certain that returned number of characters may be fetched without error, and without accessing any external device. Implemented in ASSA::ConUDPSocket, ASSA::IPv4Socket, and ASSA::UnConUDPSocket. |
|
Determine the endianess of the platform we are on.
Definition at line 625 of file Socket.cpp. 00626 { 00627 union { 00628 char c [sizeof (short)]; 00629 short v; 00630 } endian_u; 00631 00632 endian_u.v = 256; 00633 return (endian_u.c [0] == 0); 00634 }
|
|
Open socket.
Implemented in ASSA::IPv4Socket, and ASSA::UDPSocket. |
|
Convertion to void* (for testing where bool is required).
Definition at line 515 of file Socket.h. References fail(). 00516 { 00517 return fail() ? (void *)0 : (void *)(-1); 00518 }
|
|
Alias to fail().
Definition at line 521 of file Socket.h. References fail(). 00522 { 00523 return fail(); 00524 }
|
|
Manipulators plug-in operator.
Definition at line 424 of file Socket.h.
|
|
Output of built-in double type. The value will be XDR-encoded.
Definition at line 561 of file Socket.cpp. References eofbit, failbit, setstate(), and write(). 00562 { 00563 double buf, f = n_; 00564 XDR xdrs; 00565 xdrmem_create (&xdrs, (caddr_t) &buf, sizeof(double), XDR_ENCODE); 00566 xdr_double (&xdrs, &f); 00567 00568 int ret = write ((const char*) &buf, sizeof(double)); 00569 xdr_destroy (&xdrs); 00570 if ( ret != sizeof(double) ) { 00571 setstate (Socket::eofbit|Socket::failbit); 00572 } 00573 return *this; 00574 }
|
|
Output of built-in float type. The value will be XDR-encoded.
Definition at line 544 of file Socket.cpp. References eofbit, failbit, setstate(), and write(). 00545 { 00546 float buf, f = n_; 00547 XDR xdrs; 00548 xdrmem_create (&xdrs, (caddr_t) &buf, sizeof(float), XDR_ENCODE); 00549 xdr_float (&xdrs, &f); 00550 00551 int ret = write ((const char*) &buf, sizeof(float)); 00552 xdr_destroy (&xdrs); 00553 if ( ret != sizeof(float) ) { 00554 setstate (Socket::eofbit|Socket::failbit); 00555 } 00556 return *this; 00557 }
|
|
Output of built-in u_long type. The value will be XDR-encoded.
Definition at line 540 of file Socket.cpp. |
|
Output of built-in long type. The value will be XDR-encoded.
Definition at line 539 of file Socket.cpp. |
|
Output of built-in u_int type. The value will be XDR-encoded.
Definition at line 538 of file Socket.cpp. |
|
Output of built-in integer type. The value will be XDR-encoded.
Definition at line 537 of file Socket.cpp. |
|
Output of built-in u_short type. The value will be XDR-encoded.
Definition at line 502 of file Socket.cpp. References eofbit, failbit, setstate(), and write(). 00503 { 00504 u_short val = (u_short) htons((u_short)n_); 00505 00506 if (write ((const char*) &val, sizeof(u_short)) != sizeof(u_short)) 00507 { 00508 setstate (Socket::eofbit|Socket::failbit); 00509 } 00510 return *this; 00511 }
|
|
Output of built-in short type. The value will be XDR-encoded.
Definition at line 490 of file Socket.cpp. References eofbit, failbit, setstate(), and write(). 00491 { 00492 short val = (short) htons((short)n_); 00493 00494 if (write ((const char*) &val, sizeof(short)) != sizeof(short)) 00495 { 00496 setstate (Socket::eofbit|Socket::failbit); 00497 } 00498 return *this; 00499 }
|
|
Output of STL string type. The value will be XDR-encoded. 0 1 2 3 4 5 ... +-----+-----+-----+-----+-----+-----+...+-----+-----+...+-----+ | length n |byte0|byte1|...| n-1 | 0 |...| 0 | +-----+-----+-----+-----+-----+-----+...+-----+-----+...+-----+ |<-------4 bytes------->|<------n bytes------>|<---r bytes--->| |<----n+r (where (n+r) mod 4 = 0)---->| If n is not a multiple of four, then the n bytes are followed by enough (0 to 3) residual zero bytes, r, to make the total byte count a multiple of four. In other words, (4 - n % 4) == r. We follow the format, but send data bytes as-is - no conversion is required. We also pad data with r bytes. Definition at line 471 of file Socket.cpp. References eofbit, failbit, setstate(), and write(). 00472 { 00473 static const char pad [4] = { 0, 0, 0, 0 }; 00474 00475 (*this) << s_.length (); 00476 int ret = write (s_.c_str (), s_.length ()); 00477 if ( ret != s_.length () ) { 00478 setstate (Socket::eofbit|Socket::failbit); 00479 } 00480 size_t r = 4 - s_.length() % 4; 00481 if (r) { 00482 if (write (pad, r) != r) { 00483 setstate (Socket::eofbit|Socket::failbit); 00484 } 00485 } 00486 return *this; 00487 }
|
|
Output of built-in signed char type. The value will be XDR-encoded.
Definition at line 391 of file Socket.h. References operator<<().
|
|
Output of built-in u_char type. The value will be XDR-encoded.
Definition at line 385 of file Socket.h.
|
|
Output of built-in char type. The value will be XDR-encoded.
Definition at line 433 of file Socket.cpp. References eofbit, failbit, and write(). Referenced by operator<<(). 00434 { 00435 /* See comment to operator>>(char n_) */ 00436 00437 int buf = 0; 00438 int len = sizeof (int); 00439 XDR xdrs; 00440 00441 xdrmem_create (&xdrs, (caddr_t) &buf, len, XDR_ENCODE); 00442 xdr_char (&xdrs, &n_); 00443 00444 if (write ((const char*) &buf, len) != len) { 00445 (Socket::eofbit|Socket::failbit); 00446 } 00447 xdr_destroy (&xdrs); 00448 return *this; 00449 }
|
|
|
|
Input of built-in double type. The value will be XDR-decoded.
Definition at line 412 of file Socket.cpp. References eofbit, failbit, read(), and setstate(). 00413 { 00414 double val = 0; 00415 XDR xdrs; 00416 xdrmem_create (&xdrs, (caddr_t) &val, sizeof(double), XDR_DECODE); 00417 if (read ((char*) &val, sizeof(double)) == sizeof(double)) { 00418 xdr_double (&xdrs, &n_); 00419 } 00420 else { 00421 setstate (Socket::eofbit|Socket::failbit); 00422 } 00423 xdr_destroy (&xdrs); 00424 return *this; 00425 }
|
|
Input of built-in float type. The value will be XDR-decoded.
Definition at line 394 of file Socket.cpp. References eofbit, failbit, read(), and setstate(). 00395 { 00396 float val; 00397 XDR xdrs; 00398 xdrmem_create (&xdrs, (caddr_t) &val, sizeof(float), XDR_DECODE); 00399 00400 if (read ((char*) &val, sizeof(float)) == sizeof(float)) { 00401 xdr_float (&xdrs, &n_); 00402 } 00403 else { 00404 setstate (Socket::eofbit|Socket::failbit); 00405 } 00406 xdr_destroy (&xdrs); 00407 return *this; 00408 }
|
|
Input of built-in u_long type. The value will be XDR-decoded.
Definition at line 390 of file Socket.cpp. |
|
Input of built-in long type. The value will be XDR-decoded.
Definition at line 389 of file Socket.cpp. |
|
Input of built-in u_int type. The value will be XDR-decoded.
Definition at line 388 of file Socket.cpp. |
|
Input of built-in integer type. The value will be XDR-decoded.
Definition at line 387 of file Socket.cpp. |
|
Input of built-in u_short type. The value will be XDR-decoded.
Definition at line 341 of file Socket.cpp. References eofbit, failbit, read(), and setstate(). 00342 { 00343 u_short val; 00344 if (read ((char*) &val, sizeof(u_short)) == sizeof(u_short)) { 00345 n_ = (u_short) ntohs ((u_short)val); 00346 } 00347 else { 00348 setstate (Socket::eofbit|Socket::failbit); 00349 } 00350 return *this; 00351 }
|
|
Input of built-in short type. The value will be XDR-decoded.
Definition at line 327 of file Socket.cpp. References eofbit, failbit, read(), and setstate(). 00328 { 00329 short val; 00330 if (read ((char*) &val, sizeof(short)) == sizeof(short)) { 00331 n_ = (short) ntohs ((short)val); 00332 } 00333 else { 00334 setstate (Socket::eofbit|Socket::failbit); 00335 } 00336 return *this; 00337 }
|
|
Input of STL string type. The string content will be XDR-decoded.
Definition at line 306 of file Socket.cpp. References ignore(), and read(). 00307 { 00308 char c = 0; 00309 size_t n = 0; 00310 s_ = ""; 00311 00312 (*this) >> n; 00313 00314 if (n == 0) { 00315 return *this; 00316 } 00317 size_t len = n; 00318 while (len-- && read (&c, 1) == 1) { 00319 s_ += c; 00320 } 00321 ignore (4 - n % 4); 00322 return *this; 00323 }
|
|
Input of built-in signed char type. The value will be XDR-decoded.
Definition at line 349 of file Socket.h. References operator>>(). 00350 { 00351 return operator>>((char&) c_); 00352 }
|
|
Input of built-in u_char type. The value will be XDR-decoded.
Definition at line 343 of file Socket.h. References operator>>(). 00344 { 00345 return operator>>((char&) c_); 00346 }
|
|
Input of built-in char type. The value will be XDR-decoded. "xdr_char() translates between C characters and their external representations. Note: encoded characters are not packed, and occupy 4 bytes each." From SunOS 5.3 Network Interfaces Programmer's Guide, "XDR Protocol Specification": "The representation of all items requires a multipe of four bytes (or 32 bits) of data. ... The n bytes are followed by enough (0 to 3) residual zero bytes, r, to make the total byte count a multiple of four." The implication if this is that even though we transerfer 1 byte, we still have to allocate and transfer 4 bytes to hold it. Definition at line 284 of file Socket.cpp. References eofbit, failbit, read(), and setstate(). Referenced by operator>>(). 00285 { 00286 00287 int c = 0; 00288 int len = sizeof (int); 00289 XDR xdrs; 00290 xdrmem_create (&xdrs, (caddr_t) &c, len, XDR_DECODE); 00291 00292 if (read ((char* ) &c, len) == len) { 00293 xdr_char (&xdrs, &n_); 00294 } 00295 else { 00296 setstate (Socket::eofbit|Socket::failbit); 00297 } 00298 xdr_destroy(&xdrs); 00299 return *this; 00300 }
|
|
Virtual function that sets new socket buffer and returns the old one. Default behavior is to return NULL.
Reimplemented in ASSA::IPv4Socket. Definition at line 238 of file Socket.h.
|
|
Return a pointer to the Streambuf associated with the stream. This is part of the construction of a stream, and the buffer class object is not normally changed. This function may be used to get at Streambuf functionality directly, given a Socket object. Default behavior is to return NULL.
Reimplemented in ASSA::IPv4Socket. Definition at line 231 of file Socket.h. Referenced by flush(), and getBytesAvail().
|
|
Retrieve state of the socket.
Definition at line 293 of file Socket.h. References m_state. 00293 { return m_state; }
|
|
Read expected number of bytes from the socket.
Reimplemented in ASSA::ConUDPSocket, and ASSA::IPv4Socket. Definition at line 508 of file Socket.h. References ASSA::SOCKTRACE, and trace_with_mask. Referenced by ignore(), operator>>(), and ASSA::operator>>(). 00509 { 00510 trace_with_mask("Socket::read()",SOCKTRACE); 00511 return -1; 00512 }
|
|
Gateway method for setting file descriptor options.
Definition at line 81 of file Socket.cpp. References m_fd. Referenced by setOption(), turnOptionOff(), and turnOptionOn(). 00082 { 00083 int val; 00084 if ((val = fcntl (m_fd, F_GETFL, 0)) < 0) { 00085 return -1; 00086 } 00087 val |= flags_; // turn flags on 00088 00089 return (fcntl (m_fd, F_SETFL, val) < 0) ? -1 : 0; 00090 }
|
|
Gateway method of setting socket options.
Definition at line 70 of file Socket.cpp. References failbit, m_fd, and setstate(). Referenced by setOption(), turnOptionOff(), and turnOptionOn(). 00071 { 00072 int ret = setsockopt (m_fd, level_, optname_, (const char*) &val_, 00073 sizeof (val_)); 00074 if (ret < 0) 00075 setstate (Socket::failbit); 00076 return ret; 00077 }
|
|
Set socket option to value required.
Definition at line 151 of file Socket.cpp. References blocking, clear_fd_options(), EL, ASSA::ERROR, nonblocking, rcvlowat, set_fd_options(), set_option(), sndlowat, ASSA::SOCKTRACE, and trace_with_mask. 00152 { 00153 trace_with_mask("Socket::setOption(,)",SOCKTRACE); 00154 int optname; 00155 00156 if (nonblocking == opt_) 00157 return (arg_ == 1) ? set_fd_options (O_NONBLOCK) 00158 : clear_fd_options (O_NONBLOCK); 00159 00160 if (blocking == opt_) 00161 return (arg_ == 1) ? clear_fd_options (O_NONBLOCK) 00162 : set_fd_options (O_NONBLOCK); 00163 00164 if (rcvlowat == opt_) optname = SO_RCVLOWAT; 00165 else if (sndlowat == opt_) optname = SO_SNDLOWAT; 00166 else { 00167 EL((ERROR,"Invalid socket option\n")); 00168 return false; 00169 } 00170 return set_option (SOL_SOCKET, optname, arg_) == 0; 00171 }
|
|
Set socket state to flag_ by adding flag_ to the existing state.
Definition at line 534 of file Socket.h. References m_state. Referenced by ASSA::UDPSocket::bind(), ASSA::IPv4Socket::bind(), ASSA::IPv4Socket::clone(), ASSA::UDPSocket::close(), ASSA::IPv4Socket::close(), ASSA::ConUDPSocket::connect(), flush(), ignore(), ASSA::UDPSocket::open(), ASSA::IPv4Socket::open(), operator<<(), operator>>(), ASSA::ConUDPSocket::read(), and set_option(). 00535 { 00536 m_state |= flag_; 00537 }
|
|
Disable socket option.
Definition at line 129 of file Socket.cpp. References blocking, clear_fd_options(), EL, ASSA::ERROR, nonblocking, reuseaddr, set_fd_options(), set_option(), ASSA::SOCKTRACE, and trace_with_mask. 00130 { 00131 trace_with_mask("Socket::turnOptionOff",SOCKTRACE); 00132 00133 if (blocking == opt_) 00134 return set_fd_options (O_NONBLOCK); 00135 00136 if (nonblocking == opt_) 00137 return clear_fd_options (O_NONBLOCK); 00138 00139 int optname; 00140 if (reuseaddr == opt_) 00141 optname = SO_REUSEADDR; 00142 else { 00143 EL((ERROR,"Invalid socket option\n")); 00144 return false; 00145 } 00146 return set_option (SOL_SOCKET, optname, 0) == 0; 00147 }
|
|
Enable socket option.
Definition at line 107 of file Socket.cpp. References blocking, clear_fd_options(), EL, ASSA::ERROR, nonblocking, reuseaddr, set_fd_options(), set_option(), ASSA::SOCKTRACE, and trace_with_mask. Referenced by ASSA::IPv4Socket::accept(), ASSA::IPv4Socket::bind(), and ASSA::RemoteLogger::log_open(). 00108 { 00109 trace_with_mask("Socket::turnOptionOn",SOCKTRACE); 00110 00111 if (blocking == opt_) 00112 return clear_fd_options (O_NONBLOCK); 00113 00114 if (nonblocking == opt_) 00115 return set_fd_options (O_NONBLOCK); 00116 00117 int optname; 00118 if (reuseaddr == opt_) 00119 optname = SO_REUSEADDR; 00120 else { 00121 EL((ERROR,"Invalid socket option\n")); 00122 return false; 00123 } 00124 return set_option (SOL_SOCKET, optname, 1) == 0; 00125 }
|
|
Write specified number of bytes to the socket.
Reimplemented in ASSA::ConUDPSocket, and ASSA::IPv4Socket. Definition at line 501 of file Socket.h. References ASSA::SOCKTRACE, and trace_with_mask. Referenced by ASSA::endl(), ASSA::ends(), and operator<<(). 00502 { 00503 trace_with_mask("Socket::write",SOCKTRACE); 00504 return -1; 00505 }
|
|
Give the true length of the XDR-encoded STL string.
Definition at line 334 of file Socket.h. Referenced by ASSA::RemoteLogger::log_func(), ASSA::RemoteLogger::log_msg(), ASSA::RemoteLogger::log_open(), and ASSA::xdrIOBuffer::operator>>().
|
|
|
Control state of the socket.
Definition at line 459 of file Socket.h. Referenced by bad(), clear(), eof(), fail(), good(), rdstate(), and setstate(). |
|
Socket domain type.
Definition at line 456 of file Socket.h. Referenced by ASSA::UDPSocket::getDomain(), ASSA::IPv4Socket::getDomain(), ASSA::UDPSocket::open(), ASSA::IPv4Socket::open(), and ASSA::UDPSocket::setDomain(). |
|
Size of bytes of a kernel page.
Definition at line 73 of file Socket.h. Referenced by ignore(). |