/[monit]/monit/net.c
ViewVC logotype

Diff of /monit/net.c

Parent Directory Parent Directory | Revision Log Revision Log | View Patch Patch

revision 1.19 by hauk, Tue Jun 17 02:04:57 2003 UTC revision 1.20 by hauk, Thu Jul 24 00:35:25 2003 UTC
# Line 156  int check_host(char *hostname) { Line 156  int check_host(char *hostname) {
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.
# Line 202  int check_socket(int socket) { Line 179  int check_socket(int socket) {
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   */   */
# Line 221  int check_udp_socket(int socket) { Line 198  int check_udp_socket(int socket) {
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) {
# Line 474  int set_block(int socket) { Line 451  int set_block(int socket) {
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

Legend:
Removed from v.1.19  
changed lines
  Added in v.1.20

savannah-hackers-public@gnu.org
ViewVC Help
Powered by ViewVC 1.1.26