Main Page | Modules | Alphabetical List | Data Structures | File List | Data Fields | Globals | Related Pages

pinghandler.h

Go to the documentation of this file.
00001 
00002 /*
00003 ** Copyright (C) 2004 Russell Leighton
00004 **
00005 ** This program is free software; you can redistribute it and/or modify
00006 ** it under the terms of the GNU General Public License as published by
00007 ** the Free Software Foundation; either version 2 of the License, or
00008 ** (at your option) any later version.
00009 **
00010 ** This program is distributed in the hope that it will be useful,
00011 ** but WITHOUT ANY WARRANTY; without even the implied warranty of
00012 ** MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
00013 ** GNU General Public License for more details.
00014 **
00015 ** You should have received a copy of the GNU General Public License
00016 ** along with this program; if not, write to the Free Software
00017 ** Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
00018 */
00019 
00020 
00021 
00022 
00023 #ifndef __AWHANDLER_PING__
00024 #define __AWHANDLER_PING__
00025 
00026 #include "sysnet.h"
00027 #include "monitor.h"
00028 #include "wire.h"
00029 
00098 /*
00099 Changes:
00100 
00101 02/18/04  Russell Leighton
00102 Ported to handler
00103 
00104 04/16/02  Russell Leighton
00105 Made stateful.
00106 
00107 03/08/02  Russell Leighton
00108 Added triptime and packets events.
00109 
00110 12/28/01 Russell Leighton
00111 Added 'maxretries' to handler.
00112 
00113 */
00114 
00118 typedef struct {
00119 
00120   aw_event_sig_t
00121    connect,
00122    noconnect,
00123    triptime,
00124    packets;
00125 
00126   u_int32_t
00127    statefull;                    /* if non-zero then connect/noconnect events will be statefull,
00128                                     meaning you only get events on transitions from connect <-> noconnect
00129                                   */
00130 
00131 } aw_pinghandler_events_t;
00132 
00136 typedef enum {
00137 
00138   AW_PINGHANDLER_IDLE,               /* not doing anything */
00139   AW_PINGHANDLER_WAIT_READ,          /* waiting on a read() */
00140   AW_PINGHANDLER_DONE_READ,          /* done read */
00141 
00142 } aw_pinghandler_state_cd_t;
00143 
00144 
00148 typedef struct {
00149 
00150   aw_pinghandler_state_cd_t
00151    state_cd;
00152 
00153   aw_event_t
00154    *current_event;
00155 
00156   int32_t
00157    sfd;
00158 
00159   /* marks start of connection */
00160   aw_timestamp_t
00161    starttime;
00162 
00163   /* how many times have I tried */
00164   u_int32_t
00165    tries;
00166 
00167   /* 1 if last handler could connect, -1 if could noconnect */
00168   int32_t
00169    connect;
00170 
00171 } aw_pinghandler_state_t;
00172 
00176 typedef struct {
00177 
00178   aw_handler_t 
00179     handler_header;
00180 
00181   aw_pinghandler_state_t
00182    state;
00183 
00184   aw_pinghandler_events_t
00185    events;
00186 
00187   struct sockaddr_in
00188    whereto_addr;
00189 
00190   /* used for timeout callbacks */
00191   aw_address_t
00192    timeout_event_id;
00193 
00194   /* sched for timeout alarm */
00195   aw_alarm_sched_t
00196    timeout_sched;
00197 
00198   /* number of times to try before giving up , if 0 then try only 1 time */
00199   u_int32_t
00200    maxretries;
00201 
00202   byte_t
00203    *host;
00204 
00205 } aw_pinghandler_t ;
00206 
00219 aw_pinghandler_t *aw_create_pinghandler(const aw_pinghandler_events_t *events,
00220                                         const byte_t *hostname,
00221                                         aw_timestamp_t timeout,
00222                                         u_int32_t maxretries,
00223                                         int32_t (*regevent)(aw_handler_t *h, aw_address_t *eventid, u_int32_t index),
00224                                         int32_t (*regmaskevent)(aw_handler_t *h, aw_address_t *eventid, u_int32_t index),
00225                                         const aw_alarm_sched_t *sched,
00226                                         aw_logger_t *logger
00227                                         );
00228 
00233 void aw_free_pinghandler(aw_pinghandler_t *p);
00234 
00238 aw_handler_t *aw_wire_pinghandler(aw_wire_mkhandler_args_t *args);
00239 
00240 #endif
00241 
00242 
Aware 0.11.1 Copyright (C) 1998-2005 Russell Leighton (russ@elegant-software.com)