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>
27 #include <netinet/in.h>
37 /* throughput statistics */
40 double nbytes
; /* how many bytes transferred */
41 double nsec
; /* within how many seconds */
44 /* context of a relay client */
48 char mcast_addr
[ IPADDR_STR_SIZE
];
50 char src_addr
[ IPADDR_STR_SIZE
];
58 /* statistics on traffic relay & data gathering
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 */
72 char listen_addr
[ IPADDR_STR_SIZE
];
74 char mcast_ifc_addr
[ IPADDR_STR_SIZE
];
77 char cmd
[ MAX_CMD_LEN
+ 1 ];
83 u_short rcv_tmout
, /* receive/send timeout */
86 int cpipe
[ 2 ]; /* client communications pipe */
90 /* initialize server context data
93 init_server_ctx( struct server_ctx
* ctx
,
97 const char* mifc_addr
);
99 /* release server context
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
,
119 /* delete client from server context
122 delete_client( struct server_ctx
* ctx
, pid_t cpid
);
125 /* init traffic relay statistics
128 tpstat_init( struct tps_data
* d
, int setpid
);
131 /* send statistics update to server (if it's time)
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
);
148 #endif /* UDPXY_CTX_H_0111081738 */