#include <SocketStreamImplBSD.h>
Inheritance diagram for vpr::SocketStreamImplBSD:


Public Methods | |
| SocketStreamImplBSD () | |
| Constructor. More... | |
| SocketStreamImplBSD (const InetAddr &local_addr, const InetAddr &remote_addr) | |
| Constructs a stream socket using the given addresses as defaults for communication channels. More... | |
| SocketStreamImplBSD (const SocketStreamImplBSD &sock) | |
| Copy constructor. More... | |
| vpr::ReturnStatus | listen (const int backlog=5) |
| Puts this socket into the listening state where it listens for incoming connection requests. More... | |
| vpr::ReturnStatus | accept (SocketStreamImplBSD &sock, vpr::Interval timeout=vpr::Interval::NoTimeout) |
| Accepts an incoming connection request and return the connected socket to the caller in the given socket object reference. More... | |
Definition at line 58 of file SocketStreamImplBSD.h.
|
|
Constructor.
Definition at line 62 of file SocketStreamImplBSD.cpp. References vpr::SocketTypes::STREAM.
00063 : SocketImplBSD(vpr::SocketTypes::STREAM) 00064 { 00065 /* Do nothing. */ ; 00066 } |
|
||||||||||||
|
Constructs a stream socket using the given addresses as defaults for communication channels. This takes the address (either hostname or IP address) of a remote site and a port and stores the values for later use in the member variables of the object.
Definition at line 68 of file SocketStreamImplBSD.cpp. References vpr::InetAddr, and vpr::SocketTypes::STREAM.
00070 : SocketImplBSD(local_addr, remote_addr, SocketTypes::STREAM) 00071 { 00072 /* Do nothing. */ ; 00073 } |
|
|
Copy constructor.
Definition at line 75 of file SocketStreamImplBSD.cpp. References vpr::FileHandleImplUNIX::mFdesc, vpr::SocketImplBSD::mHandle, and vpr::SocketTypes::STREAM.
00076 : SocketImplBSD(sock.mLocalAddr, sock.mRemoteAddr, SocketTypes::STREAM) 00077 { 00078 mHandle = new FileHandleImplUNIX(sock.mHandle->getName()); 00079 mHandle->mFdesc = sock.mHandle->mFdesc; 00080 } |
|
|
Puts this socket into the listening state where it listens for incoming connection requests.
Definition at line 83 of file SocketStreamImplBSD.cpp. References errno, vpr::FileHandleImplUNIX::mFdesc, vpr::SocketImplBSD::mHandle, and vpr::ReturnStatus::setCode.
00084 {
00085 vpr::ReturnStatus retval;
00086
00087 // Put the socket into listning mode. If that fails, print an error and
00088 // return error status.
00089 if ( ::listen(mHandle->mFdesc, backlog) == -1 )
00090 {
00091 fprintf(stderr,
00092 "[vpr::SocketStreamImplBSD] Cannot listen on socket: %s\n",
00093 strerror(errno));
00094 retval.setCode(ReturnStatus::Fail);
00095 }
00096
00097 return retval;
00098 }
|
|
||||||||||||
|
Accepts an incoming connection request and return the connected socket to the caller in the given socket object reference.
Definition at line 101 of file SocketStreamImplBSD.cpp. References errno, vpr::InetAddr, vpr::SocketImplBSD::isBlocking, vpr::FileHandleImplUNIX::isReadable, vpr::SocketImplBSD::mBlockingFixed, vpr::FileHandleImplUNIX::mFdesc, vpr::SocketImplBSD::mHandle, vpr::ReturnStatus::setCode, and vpr::ReturnStatus::success.
00102 {
00103 int accept_sock;
00104 vpr::ReturnStatus retval;
00105 InetAddr addr;
00106 #if defined(VPR_OS_IRIX) || defined(VPR_OS_HPUX)
00107 int addrlen;
00108 #else
00109 socklen_t addrlen;
00110 #endif
00111
00112 retval = mHandle->isReadable(timeout);
00113
00114 if ( retval.success() )
00115 {
00116 mBlockingFixed = true;
00117
00118 // Accept an incoming connection request.
00119 addrlen = addr.size();
00120 accept_sock = ::accept(mHandle->mFdesc,
00121 (struct sockaddr*) &addr.mAddr, &addrlen);
00122
00123 // If accept(2) failed, print an error message and return error stauts.
00124 if ( accept_sock == -1 )
00125 {
00126 if ( errno == EWOULDBLOCK && ! isBlocking() )
00127 {
00128 retval.setCode(ReturnStatus::WouldBlock);
00129 }
00130 else
00131 {
00132 fprintf(stderr,
00133 "[vpr::SocketStreamImplBSD] Error while accepting "
00134 "incoming connection: %s\n", strerror(errno));
00135 retval.setCode(ReturnStatus::Fail);
00136 }
00137 }
00138 // Otherwise, put the new socket in the passed socket object.
00139 else
00140 {
00141 sock.setRemoteAddr(addr);
00142 sock.mHandle = new FileHandleImplUNIX(addr.getAddressString());
00143 sock.mHandle->mFdesc = accept_sock;
00144 sock.mHandle->mOpen = true;
00145
00146 sock.setBlocking(this->isBlocking());
00147
00148 sock.mBound = true;
00149 sock.mConnected = true;
00150 sock.mBlockingFixed = true;
00151 }
00152 }
00153
00154 return retval;
00155 }
|
1.2.14 written by Dimitri van Heesch,
© 1997-2002