usbmodeswitch: Updated to v.1.2.6 from shibby's branch.
[tomato.git] / release / src / router / udpxy / ctx.h
blob228e7d84527ad683b6589abd0c8d4ee8a3560314
1 /* @(#) client/server context data structures and interfaces
3 * Copyright 2008-2011 Pavel V. Cherenkov (pcherenkov@gmail.com) (pcherenkov@gmail.com)
5 * This file is part of udpxy.
7 * udpxy is free software: you can redistribute it and/or modify
8 * it under the terms of the GNU General Public License as published by
9 * the Free Software Foundation, either version 3 of the License, or
10 * (at your option) any later version.
12 * udpxy is distributed in the hope that it will be useful,
13 * but WITHOUT ANY WARRANTY; without even the implied warranty of
14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 * GNU General Public License for more details.
17 * You should have received a copy of the GNU General Public License
18 * along with udpxy. If not, see <http://www.gnu.org/licenses/>.
22 #ifndef UDPXY_CTX_H_0111081738
23 #define UDPXY_CTX_H_0111081738
25 #include <sys/types.h>
26 #include <unistd.h>
27 #include <netinet/in.h>
29 #include "udpxy.h"
30 #include "dpkt.h"
32 #ifdef __cpluspplus
33 extern "C" {
34 #endif
37 /* throughput statistics */
38 struct tput_stat {
39 int32_t sender_id;
40 double nbytes; /* how many bytes transferred */
41 double nsec; /* within how many seconds */
44 /* context of a relay client */
45 struct client_ctx
47 pid_t pid;
48 char mcast_addr[ IPADDR_STR_SIZE ];
49 uint16_t mcast_port;
50 char src_addr[ IPADDR_STR_SIZE ];
51 uint16_t src_port;
53 struct tput_stat
54 tstat;
58 /* statistics on traffic relay & data gathering
60 struct tps_data {
61 pid_t pid; /* our PID - cached */
62 time_t tm_from; /* last time update sent (successfully) */
63 double niter; /* number of iterations since last try */
64 double nbytes; /* bytes transferred since last update */
68 /* context of the server */
69 struct server_ctx
71 int lsockfd;
72 char listen_addr[ IPADDR_STR_SIZE ];
73 uint16_t listen_port;
74 char mcast_ifc_addr[ IPADDR_STR_SIZE ];
75 struct in_addr
76 mcast_inaddr;
77 char cmd[ MAX_CMD_LEN + 1 ];
79 size_t clfree,
80 clmax;
81 struct client_ctx*
82 cl;
83 u_short rcv_tmout, /* receive/send timeout */
84 snd_tmout;
86 int cpipe[ 2 ]; /* client communications pipe */
90 /* initialize server context data
92 int
93 init_server_ctx( struct server_ctx* ctx,
94 const size_t max,
95 const char* laddr,
96 uint16_t lport,
97 const char* mifc_addr );
99 /* release server context
101 void
102 free_server_ctx( struct server_ctx* ctx );
105 /* find index of the first client with the given pid
108 find_client( const struct server_ctx* ctx, pid_t pid );
111 /* add client to server context
114 add_client( struct server_ctx* ctx,
115 pid_t cpid, const char* maddr, uint16_t mport,
116 int sockfd );
119 /* delete client from server context
122 delete_client( struct server_ctx* ctx, pid_t cpid );
125 /* init traffic relay statistics
127 void
128 tpstat_init( struct tps_data* d, int setpid );
131 /* send statistics update to server (if it's time)
133 void
134 tpstat_update( struct server_ctx* ctx,
135 struct tps_data* d, ssize_t nbytes );
138 /* read client statistics data and update the context
141 tpstat_read( struct server_ctx* ctx );
144 #ifdef __cpluspplus
146 #endif
148 #endif /* UDPXY_CTX_H_0111081738 */
150 /* __EOF__ */