#include <Socket.hpp>
Inheritance diagram for Socket::
Public Methods | |
Socket (sockaddr *sa=NULL, int domain=PF_INET, int type=SOCK_STREAM, int protocol=0) throw (int) | |
Socket (Socket &original) throw (int) | |
Socket (int set_socket, int domain=PF_INET, int type=SOCK_STREAM, int protocol=0) throw (int) | |
int | bind (struct sockaddr *sa=NULL) |
int | connect (struct sockaddr *sa=NULL) |
void | close () |
void | shutdownInput () |
void | shutdownOutput () |
void | shutdown (int how=2) |
sockaddr * | getSockAddr () |
sockaddr * | getLocalSockAddr () |
int | getSocket () |
int | getDomain () |
int | getType () |
int | getProtocol () |
int | setSockOpt (int level, int optname, void *optval, socklen_t optlen) |
void * | getSockOpt (int level, int optname, void *optval, socklen_t *optlen) |
int | read (void *buffer, size_t len, int flags=0) |
int | send (void *buffer, size_t len, int flags=0) |
Protected Attributes | |
int | s_domain |
int | s_type |
int | s_protocol |
sockaddr * | rsa |
sockaddr * | lsa |
sockaddr | remote_sa |
sockaddr | local_sa |
int | sck |
|
Definition at line 15 of file Socket.cpp. 00020 { 00021 s_domain = domain; 00022 s_type = type; 00023 s_protocol = protocol; 00024 00025 rsa = NULL; 00026 lsa = NULL; 00027 00028 sck = socket( domain, type, protocol ); 00029 00030 if(sck == -1) 00031 { 00032 throw errno; 00033 } 00034 else 00035 { 00036 if(sa != NULL) 00037 { 00038 local_sa.sa_family = sa->sa_family; 00039 00040 // NOTICE: Can't you use memcpy() instead ?! 00041 for ( register int i = 0; i < 14; i++ ) 00042 { 00043 local_sa.sa_data[i] = sa->sa_data[i]; 00044 } 00045 00046 lsa = &local_sa; 00047 } 00048 else 00049 { 00050 /* local_sa.sa_family = AF_INET; 00051 memset(&(local_sa.sa_data), '\0', 14); 00052 ((struct sockaddr_in*)local_sa).sin_port = htons(0); 00053 ((struct sockaddr_in)local_Sa).sin_addr.s_addr = htonl(INADDR_ANY); 00054 lsa = &local_sa; 00055 */ 00056 } 00057 } 00058 } |
|
Definition at line 60 of file Socket.cpp. 00061 { 00062 struct sockaddr* tmp; 00063 00064 s_domain = original.getDomain(); 00065 s_type = original.getType(); 00066 s_protocol = original.getProtocol(); 00067 00068 sck = socket(s_domain,s_type,s_protocol); 00069 if(sck == -1) 00070 { 00071 throw errno; 00072 } 00073 else 00074 { 00075 tmp = original.getLocalSockAddr(); 00076 local_sa.sa_family = tmp->sa_family; 00077 for (int i = 0;i<14;i++) local_sa.sa_data[i] = tmp->sa_data[i]; 00078 tmp = original.getSockAddr(); 00079 remote_sa.sa_family = tmp->sa_family; 00080 for (int i = 0;i<14;i++) remote_sa.sa_data[i] = tmp->sa_data[i]; 00081 lsa = &local_sa; 00082 rsa = &remote_sa; 00083 } 00084 } |
|
Definition at line 86 of file Socket.cpp. 00091 { 00092 s_domain = domain; 00093 s_type = type; 00094 s_protocol = protocol; 00095 00096 lsa = NULL; 00097 rsa = NULL; 00098 sck = set_socket; 00099 int i; 00100 socklen_t socksize = sizeof(struct sockaddr); 00101 00102 i = getsockname(sck,&local_sa,&socksize); 00103 if (i == -1) 00104 { 00105 throw errno; 00106 } 00107 else 00108 { 00109 lsa = &local_sa; 00110 socksize = sizeof(struct sockaddr); 00111 i = getpeername(sck,&remote_sa,&socksize); 00112 if ((i == -1) && (errno != ENOTCONN)) 00113 { 00114 throw errno; 00115 } 00116 else 00117 { 00118 rsa = &remote_sa; 00119 } 00120 } 00121 } |
|
Definition at line 128 of file Socket.cpp. Referenced by TcpSocket::TcpSocket().
|
|
Definition at line 160 of file Socket.cpp. Referenced by main().
00161 { 00162 ::close(sck); 00163 } |
|
Definition at line 144 of file Socket.cpp. Referenced by TcpSocket::TcpSocket().
|
|
Definition at line 199 of file Socket.cpp. 00200 { 00201 return s_domain; 00202 } |
|
Definition at line 187 of file Socket.cpp. 00188 { 00189 int size = sizeof(struct sockaddr); 00190 getsockname(sck, lsa, (socklen_t *) &size); 00191 return lsa; 00192 } |
|
Definition at line 209 of file Socket.cpp. 00210 { 00211 return s_protocol; 00212 } |
|
Definition at line 180 of file Socket.cpp. 00181 { 00182 int size = sizeof(struct sockaddr); 00183 getpeername(sck, rsa, (socklen_t *) &size); 00184 return rsa; 00185 } |
|
Definition at line 222 of file Socket.cpp. Referenced by TcpSocket::getKeepAlive(), TcpSocket::getRecieveBufferSize(), TcpSocket::getSendBufferSize(), and TcpSocket::getTcpNoDelay().
00223 { 00224 int ret; 00225 ret = getsockopt(sck, level, optname, optval, optlen); 00226 if (ret != -1) 00227 { 00228 return optval; 00229 } 00230 else 00231 { 00232 return NULL; 00233 } 00234 } |
|
Definition at line 194 of file Socket.cpp. 00195 { 00196 return sck; 00197 } |
|
Definition at line 204 of file Socket.cpp. 00205 { 00206 return s_type; 00207 } |
|
Definition at line 236 of file Socket.cpp. 00237 { 00238 int l = len; 00239 l = recv(sck,buffer, len, flags); 00240 return l; 00241 } |
|
Definition at line 244 of file Socket.cpp. 00245 { 00246 int l = len; 00247 l = ::send(sck,buffer, len, flags); 00248 return l; 00249 } |
|
Definition at line 214 of file Socket.cpp. Referenced by TcpSocket::getSoLinger(), TcpSocket::setKeepAlive(), TcpSocket::setRecieveBufferSize(), TcpSocket::setSendBufferSize(), TcpSocket::setSoLinger(), TcpSocket::setSoTimeout(), and TcpSocket::setTcpNoDelay().
00215 { 00216 int ret; 00217 ret = setsockopt(sck, level, optname, optval, optlen); 00218 return ret; 00219 } |
|
Definition at line 165 of file Socket.cpp. 00166 { 00167 ::shutdown(sck, how); 00168 } |
|
Definition at line 170 of file Socket.cpp. 00171 { 00172 ::shutdown(sck, 0); 00173 } |
|
Definition at line 175 of file Socket.cpp. 00176 { 00177 ::shutdown(sck, 1); 00178 } |
|
Definition at line 47 of file Socket.hpp. |
|
Definition at line 45 of file Socket.hpp. |
|
Definition at line 46 of file Socket.hpp. |
|
Definition at line 44 of file Socket.hpp. |
|
Definition at line 43 of file Socket.hpp. |
|
Definition at line 43 of file Socket.hpp. |
|
Definition at line 43 of file Socket.hpp. |
|
Definition at line 48 of file Socket.hpp. |