1 #ifndef cfgh
2 #define cfgh
3 
4 #include <stdio.h>
5 #include <string.h>
6 #include <unistd.h>
7 #include <assert.h>
8 #include <stdlib.h>
9 #include <limits.h>
10 #include <sys/types.h>
11 #include <sys/socket.h>
12 #include <sys/param.h>
13 #include <netinet/in.h>
14 #include <netdb.h>
15 #include <errno.h>
16 #include <pthread.h>
17 
18 #include <signal.h>
19 #include "util.h"
20 
21 #define kfootsize ( 2048 * 1024 ) // 2M is experimentally nice; however a PMC driven cache/use study  would be great to inform this
22 #define kthreadmax 16
23 
24 struct txconf_s;  // forward decl to permit inception
25 struct rxconf_s;  // forward decl to permit inception
26 
27 #define preamble_cannon_ul 0xa5a5a5a55a5a5a5a
28 	// opcodes for signaling oob status to remote end
29 #define feed_more 0xcafe
30 #define end_of_millipede 0xdead
31 // the bearer channel header
32 struct millipacket_s {
33 	unsigned long preamble;	// == preamble_cannon_ul constant,  mostly superstition against getting alien transmissions
34 	unsigned long leg_id; 	// leg_id= ( streampos  % leg_size ) is the main sequencer for the whole session
35 				// this may result in max transmission size of klegsize * ( unsigned int max )
36 				// XXX debug  sequencer rollover condition if this is a problem
37 	unsigned long size; 	// <= kfootsize
38 	unsigned long checksum; //  checksum = mix ( leg_id, opcode, sample ( payload) );
39 	int 	opcode;
40 
41 };
42 struct txworker_s {
43 	int id;
44 	struct txconf_s *txconf_parent;
45 	char state;
46 	pthread_mutex_t mutex;
47 	pthread_t thread;
48 	int sockfd ;
49 	u_char * buffer;
50 	struct millipacket_s pkt;
51 	int writeremainder;
52 
53 };
54 
55 struct target_port_s {
56 	char * name;
57 	unsigned short port ;
58 };
59 struct txconf_s {
60 	int worker_count;
61 	struct timespec ticker;
62 	u_long stream_total_bytes;
63 	struct txworker_s workers[kthreadmax];	//XXX make dynamic???
64 	int target_port_count;
65 	int target_port_cursor;
66 	struct target_port_s target_ports[kthreadmax];
67 	pthread_mutex_t mutex;
68 	int done;
69 };
70 
71 
72 
73 struct rxworker_s {
74 	int id;
75 	int sockfd;
76 	int socknum;
77 	struct rxconf_s *rxconf_parent;
78 	pthread_mutex_t mutex;
79 	pthread_t thread;
80 };
81 struct rxconf_s {
82 	int workercount;
83 	struct sockaddr_in sa;  // reusable bound sa for later accepts
84 	pthread_mutex_t  sa_mutex;  //
85 	int socknum ;  // reusable bound socket number  later accepts
86 	unsigned short port;
87 	struct rxworker_s workers[kthreadmax];
88 	int next_leg ;  // main sequencer to monotonically order legs to stdout
89 	int done_mbox;
90 	pthread_mutex_t rxmutex;
91 } ;
92 
93 
94 #endif
95