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

tcphandler.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_TCP__
00024 #define __AWHANDLER_TCP__
00025 
00026 #include "sysnet.h" 
00027 #include "monitor.h"
00028 #include "wire.h"
00029 
00096 /*
00097 
00098 Changes:
00099 
00100 04/16/02  Russell Leighton
00101 Made stateful.
00102 
00103 03/08/02 Russell Leighton
00104 Added triptime: support
00105 
00106 */
00107 
00108 
00112 typedef struct {
00113 
00114   aw_event_sig_t
00115    connect,              /* could connect() to ip:port */
00116    noconnect,            /* could NOT connect() to ip:port */
00117    triptime;             /* time it took to connect() */
00118 
00119   u_int32_t
00120    statefull;            /* if non-zero then connect/noconnect events will be statefull,
00121                             meaning you only get events on transitions from connect <-> noconnect
00122                           */
00123 
00124 } aw_tcphandler_events_t;
00125 
00129 typedef enum {
00130 
00131   AW_TCPHANDLER_IDLE,               /* not doing anything */
00132   AW_TCPHANDLER_WAIT_CONNECT,       /* waiting on a connect() */
00133   AW_TCPHANDLER_DONE_CONNECT        /* done read */
00134 
00135 } aw_tcphandler_state_cd_t;
00136 
00137 
00141 typedef struct {
00142 
00143   aw_tcphandler_state_cd_t
00144    state_cd;
00145 
00146   aw_event_t
00147    *current_event;
00148 
00149   /* socket fd, note: -1 => initial state */
00150   int32_t
00151    sfd;
00152 
00153   /* marks start of connection */
00154   aw_timestamp_t
00155    starttime;
00156 
00157   /* 1 if last handler could connect, -1 if noconnect */
00158   int32_t
00159    connect;
00160 
00161 } aw_tcphandler_state_t;
00162 
00163 
00167 typedef struct {
00168 
00169   aw_handler_t 
00170     handler_header;
00171 
00172   aw_tcphandler_state_t
00173    state;
00174 
00175   aw_tcphandler_events_t
00176    events;
00177 
00178   struct sockaddr_in
00179     service_addr;
00180 
00181   /* used for timeout callbacks */
00182   aw_address_t
00183    timeout_event_id;
00184 
00185   /* sched for timeout alarm */
00186   aw_alarm_sched_t
00187    timeout_sched;
00188 
00189   byte_t
00190    *host_n_port;
00191 
00192 } aw_tcphandler_t ;
00193 
00206 aw_tcphandler_t *aw_create_tcphandler(const aw_tcphandler_events_t *events,
00207                                       const byte_t *hostname,
00208                                       u_int32_t port,
00209                                       aw_timestamp_t timeout,
00210                                       int32_t (*regevent)(aw_handler_t *h, aw_address_t *eventid, u_int32_t index),
00211                                       int32_t (*regmaskevent)(aw_handler_t *h, aw_address_t *eventid, u_int32_t index),
00212                                       const aw_alarm_sched_t *sched,
00213                                       aw_logger_t *logger
00214                                       );
00215 
00220 void aw_free_tcphandler(aw_tcphandler_t *p);
00221 
00225 aw_handler_t *aw_wire_tcphandler(aw_wire_mkhandler_args_t *args);
00226 
00227 #endif
00228 
00229 
Aware 0.11.1 Copyright (C) 1998-2005 Russell Leighton (russ@elegant-software.com)