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

Diff of /monit/net.c

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

revision 1.66 by hauk, Sun Oct 30 01:12:05 2005 UTC revision 1.67 by hauk, Mon Oct 31 16:55:24 2005 UTC
# Line 183  int check_socket(int socket) { Line 183  int check_socket(int socket) {
183    
184    
185  /**  /**
186   * Verify that the udp socket is ready for i|o. The given socket must   * Verify that the udp server is up. The given socket must be a
187   * be a connected udp socket if we should be able to test the udp   * connected udp socket if we should be able to test the udp server.
188   * server. The test is conducted by sending one byte to the server and   * The test is conducted by sending a datagram to the server and
189   * check for a returned ICMP error when reading from the socket. A   * check for a returned ICMP error when reading from the socket.
  * better test would be to send an empty SYN udp package to avoid  
  * possibly raising an error from the server we are testing but  
  * assembling an udp by hand requires SOCKET_RAW and running the  
  * program as root.  
190   * @param socket A socket   * @param socket A socket
191   * @return TRUE if the socket is ready, otherwise FALSE.   * @return TRUE if the socket is ready, otherwise FALSE.
192   */   */
193  int check_udp_socket(int socket) {  int check_udp_socket(int socket) {
194      
195      char buf[STRLEN]= {0};
196    
197    int r;    /* We have to send something and if the UDP server is down/unreachable
198    char buf[1]= {0};     *  the remote host should send an ICMP error. We then need to call read
199       *  to get the ICMP error as a ECONNREFUSED errno. This test is asynchronous
200    /*     *  so we must wait, but we do not want to block to long either and it is
201     * R/W is asynchronous and we should probably loop and wait longer     *  probably better to report a server falsely up than to block to long.
    * for a possible ICMP error.  
202     */     */
203    write(socket, buf, 1);    sock_write(socket, buf, 1, 0);
204    sleep(2);    if(sock_read(socket, buf, STRLEN, 2) < 0) {
   r= read(socket, buf, 1);  
   if(0>r) {  
205      switch(errno) {      switch(errno) {
206      case ECONNREFUSED: return FALSE;        case ECONNREFUSED: return FALSE;
207      default:           break;        default:           break;
208      }      }
209    }    }
210        
211    return TRUE;    return TRUE;
212      
213  }  }
214    
215    

Legend:
Removed from v.1.66  
changed lines
  Added in v.1.67

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