156 |
|
|
157 |
|
|
158 |
/** |
/** |
|
* Verify that the socket connection is ready for i|o. This test use |
|
|
* select for a stream based socket. For a dgram sockets the testing |
|
|
* technique is to send a 0 byte udp packet and "check" for an ICMP |
|
|
* error. |
|
|
* @param p A Port object |
|
|
* @return TRUE if the socket is ready, otherwise FALSE. |
|
|
*/ |
|
|
int check_connection_io(Port_T p) { |
|
|
|
|
|
ASSERT(p); |
|
|
|
|
|
switch(p->type) { |
|
|
case SOCK_STREAM: return check_socket(p->socket); |
|
|
case SOCK_DGRAM: return check_udp_socket(p->socket); |
|
|
default: break; |
|
|
} |
|
|
|
|
|
return FALSE; |
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
/** |
|
159 |
* Verify that the socket is ready for i|o |
* Verify that the socket is ready for i|o |
160 |
* @param socket A socket |
* @param socket A socket |
161 |
* @return TRUE if the socket is ready, otherwise FALSE. |
* @return TRUE if the socket is ready, otherwise FALSE. |
179 |
/** |
/** |
180 |
* Verify that the udp socket is ready for i|o. The given socket must |
* Verify that the udp socket is ready for i|o. The given socket must |
181 |
* be a connected udp socket. The test is conducted by sending one |
* be a connected udp socket. The test is conducted by sending one |
182 |
* byte to the server and check for any returned ICMP error when |
* byte to the server and check for a returned ICMP error when reading |
183 |
* reading from the socket. A better test would be to send an empty |
* from the socket. A better test would be to send an empty SYN udp |
184 |
* SYN udp package to avoid possibly raising an error from the server |
* package to avoid possibly raising an error from the server we are |
185 |
* we are testing but assembling an udp by hand requires SOCKET_RAW |
* testing but assembling an udp by hand requires SOCKET_RAW and |
186 |
* and running the program as root. |
* running the program as root. |
187 |
* @param socket A socket |
* @param socket A socket |
188 |
* @return TRUE if the socket is ready, otherwise FALSE. |
* @return TRUE if the socket is ready, otherwise FALSE. |
189 |
*/ |
*/ |
198 |
*/ |
*/ |
199 |
set_noblock(socket); |
set_noblock(socket); |
200 |
write(socket, buf, 1); |
write(socket, buf, 1); |
201 |
sleep(1); |
sleep(2); |
202 |
r= read(socket, buf, 1); |
r= read(socket, buf, 1); |
203 |
set_block(socket); |
set_block(socket); |
204 |
if(0>r) { |
if(0>r) { |
451 |
|
|
452 |
} |
} |
453 |
|
|
|
/** |
|
|
* Send the message 'msg' down a port in non-blocking mode and |
|
|
* with failover. Uses SSL if necessary. |
|
|
* @param p port handler |
|
|
* @param msg The message to send |
|
|
* @param len The length of the message in bytes |
|
|
* @param flags Optional send flags |
|
|
* @return The bytes sent or -1 if an error occured |
|
|
*/ |
|
|
int port_send(Port_T p, const char *msg, int len, int flags) { |
|
|
|
|
|
ASSERT(p); |
|
|
ASSERT(msg); |
|
|
|
|
|
if (p->ssl!=NULL) { |
|
|
|
|
|
return send_ssl_socket(p->ssl, (void *) msg, len); |
|
|
|
|
|
} else { |
|
|
|
|
|
return sock_send(p->socket, msg, len, flags); |
|
|
|
|
|
} |
|
|
|
|
|
} |
|
|
|
|
|
/** |
|
|
* Read a message from the socket in non-blocking mode and |
|
|
* with failover. Uses SSL if necessary. |
|
|
* @param sock A port handler |
|
|
* @param buf The buffer to read a message into |
|
|
* @param len The length of the buffer |
|
|
* @param flags Optional recv flags |
|
|
* @return Returns the bytes read or -1 if an error occured |
|
|
*/ |
|
|
int port_recv(Port_T p, char *buf, int len, int flags) { |
|
|
|
|
|
ASSERT(p); |
|
|
ASSERT(buf); |
|
|
|
|
|
if (p->ssl!=NULL) { |
|
|
int error; |
|
|
error = recv_ssl_socket(p->ssl, buf, len); |
|
|
|
|
|
return error; |
|
|
|
|
|
} else { |
|
|
|
|
|
return sock_recv(p->socket, buf, len, flags); |
|
|
|
|
|
} |
|
|
} |
|
|
|
|
454 |
|
|
455 |
/** |
/** |
456 |
* Send the message 'msg' down the socket in non-blocking mode and |
* Send the message 'msg' down the socket in non-blocking mode and |