#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(), ASSA::IPv4Socket::clone(), ASSA::IPv4Socket::connect(), ASSA::UDPSocket::open(), and ASSA::IPv4Socket::open(). 00529 { 00530 m_state = m_fd >=0 ? state_ : state_ | Socket::badbit; 00531 }
|
|
Gateway method for clearing file descriptor options.
Definition at line 99 of file Socket.cpp. References m_fd. Referenced by setOption(), turnOptionOff(), and turnOptionOn(). 00100 { 00101 int val; 00102 if ((val = fcntl (m_fd, F_GETFL, 0)) < 0) { 00103 return -1; 00104 } 00105 val &= ~flags_; // turn flags off 00106 00107 return (fcntl (m_fd, F_SETFL, val) < 0) ? -1 : 0; 00108 }
|
|
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 583 of file Socket.cpp. References DL, ASSA::ends(), getOption(), nonblocking, ASSA::SOCKTRACE, and trace_with_mask. 00584 { 00585 trace_with_mask("Socket::dumpState",SOCKTRACE); 00586 00587 char state_set[] = "[ set]\n"; 00588 char state_not_set[] = "[not set]\n"; 00589 00590 std::ostringstream msg; 00591 00592 msg << "\n"; 00593 msg << "\tTesting good() ....... "; 00594 00595 if (this->good ()) msg << state_set; 00596 else msg << state_not_set; 00597 00598 msg << "\tTesting eof() ........ "; 00599 if (this->eof ()) msg << state_set; 00600 else msg << state_not_set; 00601 00602 msg << "\tTesting fail() ....... "; 00603 if (this->fail ()) msg << state_set; 00604 else msg << state_not_set; 00605 00606 msg << "\tTesting bad() ........ "; 00607 if (this->bad ()) msg << state_set; 00608 else msg << state_not_set; 00609 00610 msg << "\tTesting !() .......... "; 00611 if ( !(*this) ) msg << state_set; 00612 else msg << state_not_set; 00613 00614 msg << "\tTesting void *() ..... "; 00615 if ( *this ) msg << state_set; 00616 else msg << state_not_set; 00617 00618 msg << "\tTesting nonblocking... "; 00619 if (getOption (nonblocking) == 1) msg << state_set; 00620 else msg << state_not_set; 00621 00622 /*--- Terminate stream buffer ---*/ 00623 msg << std::ends; 00624 00625 DL((SOCKTRACE,"%s\n", msg.str ().c_str ())); 00626 }
|
|
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 63 of file Socket.cpp. References badbit, good(), rdbuf(), and setstate(). Referenced by ASSA::IPv4Socket::close(), ASSA::endl(), and ASSA::flush(). 00064 { 00065 if (good () && rdbuf ()) { 00066 if (rdbuf ()->pubsync () == EOF) { 00067 setstate (badbit); 00068 } 00069 } 00070 return (*this); 00071 }
|
|
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 43 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(). 00044 { 00045 trace_with_mask("Socket::getBytesAvail",SOCKTRACE); 00046 00047 Socket* This = (Socket*) this; 00048 int ba = 0; 00049 int ret = ioctl (m_fd, FIONREAD, &ba); 00050 00051 if (ret == -1) { 00052 EL((ERROR,"ioctl(2) failed with ret: %d\n", ret)); 00053 return ret; 00054 } 00055 ba += This->rdbuf ()->in_avail (); 00056 00057 DL((SOCKTRACE,"%d bytes available for reading\n", ba)); 00058 return ba; 00059 }
|
|
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 180 of file Socket.cpp. References blocking, EL, ASSA::ERROR, m_fd, nonblocking, rcvlowat, reuseaddr, sndlowat, ASSA::SOCKTRACE, and trace_with_mask. Referenced by dumpState(). 00181 { 00182 trace_with_mask("Socket::getOption",SOCKTRACE); 00183 int optval = 0; 00184 00185 if (nonblocking == opt_) { 00186 if ((optval = fcntl (m_fd, F_GETFL, 0)) < 0) { 00187 return -1; 00188 } 00189 return ((optval & O_NONBLOCK) == O_NONBLOCK ? 1 : 0); 00190 } 00191 00192 if (blocking == opt_) { 00193 if ((optval = fcntl (m_fd, F_GETFL, 0)) < 0) { 00194 return -1; 00195 } 00196 return ((optval & O_NONBLOCK) == O_NONBLOCK ? 0 : 1); 00197 } 00198 00199 int optname; 00200 int level = SOL_SOCKET; 00201 bool bin = false; 00202 00203 socklen_t len = sizeof (optval); 00204 int ret; 00205 00206 if (rcvlowat == opt_) { 00207 optname = SO_RCVLOWAT; 00208 } 00209 else if (sndlowat == opt_) { 00210 optname = SO_SNDLOWAT; 00211 } 00212 else if (reuseaddr == opt_) { 00213 optname = SO_REUSEADDR; 00214 bin = true; 00215 } 00216 else { 00217 EL((ERROR,"Invalid socket option\n")); 00218 return (-1); 00219 } 00220 00221 #ifndef __CYGWIN32__ 00222 ret = getsockopt (m_fd, level, optname, (char*) &optval, &len); 00223 #else 00224 ret = getsockopt (m_fd, level, optname, (char*) &optval, (int*)&len); 00225 #endif 00226 00227 if (ret < 0) { 00228 return (-1); 00229 } 00230 if (bin) { 00231 return (ret == 0 ? 0 : 1); 00232 } 00233 return (ret); 00234 }
|
|
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 238 of file Socket.cpp. References eofbit, failbit, PGSIZE, read(), setstate(), ASSA::SOCKTRACE, and trace_with_mask. Referenced by operator>>(). 00239 { 00240 trace_with_mask("Socket::ignore",SOCKTRACE); 00241 register int b; 00242 register int count = 0; 00243 register char c; 00244 00245 if (n_ == INT_MAX && delim_ == EOF) { 00246 char buf[PGSIZE]; 00247 while ((b = read (buf, PGSIZE))) { 00248 count += b; 00249 } 00250 setstate (Socket::eofbit|Socket::failbit); 00251 return count; 00252 } 00253 for (; n_; n_--, count++) { 00254 if ( (b = read (&c, 1)) == 0 ) { 00255 setstate (Socket::eofbit|Socket::failbit); 00256 break; 00257 } 00258 if ( c == delim_ ) 00259 break; 00260 } 00261 return count; 00262 }
|
|
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 630 of file Socket.cpp. 00631 { 00632 union { 00633 char c [sizeof (short)]; 00634 short v; 00635 } endian_u; 00636 00637 endian_u.v = 256; 00638 return (endian_u.c [0] == 0); 00639 }
|
|
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 566 of file Socket.cpp. References eofbit, failbit, setstate(), and write(). 00567 { 00568 double buf, f = n_; 00569 XDR xdrs; 00570 xdrmem_create (&xdrs, (caddr_t) &buf, sizeof(double), XDR_ENCODE); 00571 xdr_double (&xdrs, &f); 00572 00573 int ret = write ((const char*) &buf, sizeof(double)); 00574 xdr_destroy (&xdrs); 00575 if ( ret != sizeof(double) ) { 00576 setstate (Socket::eofbit|Socket::failbit); 00577 } 00578 return *this; 00579 }
|
|
Output of built-in float type. The value will be XDR-encoded.
Definition at line 549 of file Socket.cpp. References eofbit, failbit, setstate(), and write(). 00550 { 00551 float buf, f = n_; 00552 XDR xdrs; 00553 xdrmem_create (&xdrs, (caddr_t) &buf, sizeof(float), XDR_ENCODE); 00554 xdr_float (&xdrs, &f); 00555 00556 int ret = write ((const char*) &buf, sizeof(float)); 00557 xdr_destroy (&xdrs); 00558 if ( ret != sizeof(float) ) { 00559 setstate (Socket::eofbit|Socket::failbit); 00560 } 00561 return *this; 00562 }
|
|
Output of built-in u_long type. The value will be XDR-encoded.
Definition at line 545 of file Socket.cpp. |
|
Output of built-in long type. The value will be XDR-encoded.
Definition at line 544 of file Socket.cpp. |
|
Output of built-in u_int type. The value will be XDR-encoded.
Definition at line 543 of file Socket.cpp. |
|
Output of built-in integer type. The value will be XDR-encoded.
Definition at line 542 of file Socket.cpp. |
|
Output of built-in u_short type. The value will be XDR-encoded.
Definition at line 507 of file Socket.cpp. References eofbit, failbit, setstate(), and write(). 00508 { 00509 u_short val = (u_short) htons((u_short)n_); 00510 00511 if (write ((const char*) &val, sizeof(u_short)) != sizeof(u_short)) 00512 { 00513 setstate (Socket::eofbit|Socket::failbit); 00514 } 00515 return *this; 00516 }
|
|
Output of built-in short type. The value will be XDR-encoded.
Definition at line 495 of file Socket.cpp. References eofbit, failbit, setstate(), and write(). 00496 { 00497 short val = (short) htons((short)n_); 00498 00499 if (write ((const char*) &val, sizeof(short)) != sizeof(short)) 00500 { 00501 setstate (Socket::eofbit|Socket::failbit); 00502 } 00503 return *this; 00504 }
|
|
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 476 of file Socket.cpp. References eofbit, failbit, setstate(), and write(). 00477 { 00478 static const char pad [4] = { 0, 0, 0, 0 }; 00479 00480 (*this) << s_.length (); 00481 int ret = write (s_.c_str (), s_.length ()); 00482 if ( ret != s_.length () ) { 00483 setstate (Socket::eofbit|Socket::failbit); 00484 } 00485 size_t r = 4 - s_.length() % 4; 00486 if (r) { 00487 if (write (pad, r) != r) { 00488 setstate (Socket::eofbit|Socket::failbit); 00489 } 00490 } 00491 return *this; 00492 }
|
|
Output of built-in signed char type. The value will be XDR-encoded.
Definition at line 391 of file Socket.h.
|
|
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 438 of file Socket.cpp. References eofbit, failbit, and write(). 00439 { 00440 /* See comment to operator>>(char n_) */ 00441 00442 int buf = 0; 00443 int len = sizeof (int); 00444 XDR xdrs; 00445 00446 xdrmem_create (&xdrs, (caddr_t) &buf, len, XDR_ENCODE); 00447 xdr_char (&xdrs, &n_); 00448 00449 if (write ((const char*) &buf, len) != len) { 00450 (Socket::eofbit|Socket::failbit); 00451 } 00452 xdr_destroy (&xdrs); 00453 return *this; 00454 }
|
|
|
|
Input of built-in double type. The value will be XDR-decoded.
Definition at line 417 of file Socket.cpp. References eofbit, failbit, read(), and setstate(). 00418 { 00419 double val = 0; 00420 XDR xdrs; 00421 xdrmem_create (&xdrs, (caddr_t) &val, sizeof(double), XDR_DECODE); 00422 if (read ((char*) &val, sizeof(double)) == sizeof(double)) { 00423 xdr_double (&xdrs, &n_); 00424 } 00425 else { 00426 setstate (Socket::eofbit|Socket::failbit); 00427 } 00428 xdr_destroy (&xdrs); 00429 return *this; 00430 }
|
|
Input of built-in float type. The value will be XDR-decoded.
Definition at line 399 of file Socket.cpp. References eofbit, failbit, read(), and setstate(). 00400 { 00401 float val; 00402 XDR xdrs; 00403 xdrmem_create (&xdrs, (caddr_t) &val, sizeof(float), XDR_DECODE); 00404 00405 if (read ((char*) &val, sizeof(float)) == sizeof(float)) { 00406 xdr_float (&xdrs, &n_); 00407 } 00408 else { 00409 setstate (Socket::eofbit|Socket::failbit); 00410 } 00411 xdr_destroy (&xdrs); 00412 return *this; 00413 }
|
|
Input of built-in u_long type. The value will be XDR-decoded.
Definition at line 395 of file Socket.cpp. |
|
Input of built-in long type. The value will be XDR-decoded.
Definition at line 394 of file Socket.cpp. |
|
Input of built-in u_int type. The value will be XDR-decoded.
Definition at line 393 of file Socket.cpp. |
|
Input of built-in integer type. The value will be XDR-decoded.
Definition at line 392 of file Socket.cpp. |
|
Input of built-in u_short type. The value will be XDR-decoded.
Definition at line 346 of file Socket.cpp. References eofbit, failbit, read(), and setstate(). 00347 { 00348 u_short val; 00349 if (read ((char*) &val, sizeof(u_short)) == sizeof(u_short)) { 00350 n_ = (u_short) ntohs ((u_short)val); 00351 } 00352 else { 00353 setstate (Socket::eofbit|Socket::failbit); 00354 } 00355 return *this; 00356 }
|
|
Input of built-in short type. The value will be XDR-decoded.
Definition at line 332 of file Socket.cpp. References eofbit, failbit, read(), and setstate(). 00333 { 00334 short val; 00335 if (read ((char*) &val, sizeof(short)) == sizeof(short)) { 00336 n_ = (short) ntohs ((short)val); 00337 } 00338 else { 00339 setstate (Socket::eofbit|Socket::failbit); 00340 } 00341 return *this; 00342 }
|
|
Input of STL string type. The string content will be XDR-decoded.
Definition at line 311 of file Socket.cpp. References ignore(), and read(). 00312 { 00313 char c = 0; 00314 size_t n = 0; 00315 s_ = ""; 00316 00317 (*this) >> n; 00318 00319 if (n == 0) { 00320 return *this; 00321 } 00322 size_t len = n; 00323 while (len-- && read (&c, 1) == 1) { 00324 s_ += c; 00325 } 00326 ignore (4 - n % 4); 00327 return *this; 00328 }
|
|
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 289 of file Socket.cpp. References eofbit, failbit, read(), and setstate(). Referenced by operator>>(). 00290 { 00291 00292 int c = 0; 00293 int len = sizeof (int); 00294 XDR xdrs; 00295 xdrmem_create (&xdrs, (caddr_t) &c, len, XDR_DECODE); 00296 00297 if (read ((char* ) &c, len) == len) { 00298 xdr_char (&xdrs, &n_); 00299 } 00300 else { 00301 setstate (Socket::eofbit|Socket::failbit); 00302 } 00303 xdr_destroy(&xdrs); 00304 return *this; 00305 }
|
|
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(), ASSA::operator>>(), and operator>>(). 00509 { 00510 trace_with_mask("Socket::read()",SOCKTRACE); 00511 return -1; 00512 }
|
|
Gateway method for setting file descriptor options.
Definition at line 86 of file Socket.cpp. References m_fd. Referenced by setOption(), turnOptionOff(), and turnOptionOn(). 00087 { 00088 int val; 00089 if ((val = fcntl (m_fd, F_GETFL, 0)) < 0) { 00090 return -1; 00091 } 00092 val |= flags_; // turn flags on 00093 00094 return (fcntl (m_fd, F_SETFL, val) < 0) ? -1 : 0; 00095 }
|
|
Gateway method of setting socket options.
Definition at line 75 of file Socket.cpp. References failbit, m_fd, and setstate(). Referenced by setOption(), turnOptionOff(), and turnOptionOn(). 00076 { 00077 int ret = setsockopt (m_fd, level_, optname_, (const char*) &val_, 00078 sizeof (val_)); 00079 if (ret < 0) 00080 setstate (Socket::failbit); 00081 return ret; 00082 }
|
|
Set socket option to value required.
Definition at line 156 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. 00157 { 00158 trace_with_mask("Socket::setOption(,)",SOCKTRACE); 00159 int optname; 00160 00161 if (nonblocking == opt_) 00162 return (arg_ == 1) ? set_fd_options (O_NONBLOCK) 00163 : clear_fd_options (O_NONBLOCK); 00164 00165 if (blocking == opt_) 00166 return (arg_ == 1) ? clear_fd_options (O_NONBLOCK) 00167 : set_fd_options (O_NONBLOCK); 00168 00169 if (rcvlowat == opt_) optname = SO_RCVLOWAT; 00170 else if (sndlowat == opt_) optname = SO_SNDLOWAT; 00171 else { 00172 EL((ERROR,"Invalid socket option\n")); 00173 return false; 00174 } 00175 return set_option (SOL_SOCKET, optname, arg_) == 0; 00176 }
|
|
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 134 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. 00135 { 00136 trace_with_mask("Socket::turnOptionOff",SOCKTRACE); 00137 00138 if (blocking == opt_) 00139 return set_fd_options (O_NONBLOCK); 00140 00141 if (nonblocking == opt_) 00142 return clear_fd_options (O_NONBLOCK); 00143 00144 int optname; 00145 if (reuseaddr == opt_) 00146 optname = SO_REUSEADDR; 00147 else { 00148 EL((ERROR,"Invalid socket option\n")); 00149 return false; 00150 } 00151 return set_option (SOL_SOCKET, optname, 0) == 0; 00152 }
|
|
Enable socket option.
Definition at line 112 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(), ASSA::RemoteLogger::log_open(), and ASSA::IPv4Socket::open(). 00113 { 00114 trace_with_mask("Socket::turnOptionOn",SOCKTRACE); 00115 00116 if (blocking == opt_) 00117 return clear_fd_options (O_NONBLOCK); 00118 00119 if (nonblocking == opt_) 00120 return set_fd_options (O_NONBLOCK); 00121 00122 int optname; 00123 if (reuseaddr == opt_) 00124 optname = SO_REUSEADDR; 00125 else { 00126 EL((ERROR,"Invalid socket option\n")); 00127 return false; 00128 } 00129 return set_option (SOL_SOCKET, optname, 1) == 0; 00130 }
|
|
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(). |