initial load of upstream version 1.06.32
[xmlrpc-c] / lib / abyss / src / conn.h
1 #ifndef CONN_H_INCLUDED
2 #define CONN_H_INCLUDED
3
4 #include "xmlrpc-c/abyss.h"
5 #include "socket.h"
6 #include "file.h"
7
8 #define BUFFER_SIZE 4096 
9
10 struct _TConn {
11     struct _TConn * nextOutstandingP;
12         /* Link to the next connection in the list of outstanding
13            connections
14         */
15     TServer * server;
16     uint32_t buffersize;
17         /* Index into the connection buffer (buffer[], below) where
18            the next byte read on the connection will go.
19         */
20     uint32_t bufferpos;
21         /* Index into the connection buffer (buffer[], below) where
22            the next byte to be delivered to the user is.
23         */
24     uint32_t inbytes,outbytes;  
25     TSocket * socketP;
26     TIPAddr peerip;
27     abyss_bool hasOwnThread;
28     TThread * threadP;
29     abyss_bool finished;
30         /* We have done all the processing there is to do on this
31            connection, other than possibly notifying someone that we're
32            done.  One thing this signifies is that any thread or process
33            that the connection spawned is dead or will be dead soon, so
34            one could reasonably wait for it to be dead, e.g. with
35            pthread_join().  Note that one can scan a bunch of processes
36            for 'finished' status, but sometimes can't scan a bunch of
37            threads for liveness.
38         */
39     const char * trace;
40     TThreadProc * job;
41     TThreadDoneFn * done;
42     char buffer[BUFFER_SIZE];
43 };
44
45 typedef struct _TConn TConn;
46
47 TConn * ConnAlloc(void);
48
49 void ConnFree(TConn * const connectionP);
50
51 void
52 ConnCreate(TConn **            const connectionPP,
53            TServer *           const serverP,
54            TSocket *           const connectedSocketP,
55            TThreadProc *       const job,
56            TThreadDoneFn *     const done,
57            enum abyss_foreback const foregroundBackground,
58            abyss_bool          const useSigchld,
59            const char **       const errorP);
60
61 abyss_bool
62 ConnProcess(TConn * const connectionP);
63
64 abyss_bool
65 ConnKill(TConn * const connectionP);
66
67 void
68 ConnWaitAndRelease(TConn * const connectionP);
69
70 abyss_bool
71 ConnWrite(TConn *      const connectionP,
72           const void * const buffer,
73           uint32_t     const size);
74
75 abyss_bool
76 ConnRead(TConn *  const c,
77          uint32_t const timems);
78
79 void
80 ConnReadInit(TConn * const connectionP);
81
82 abyss_bool
83 ConnReadHeader(TConn * const connectionP,
84                char ** const headerP);
85
86 abyss_bool
87 ConnWriteFromFile(TConn *  const connectionP,
88                   TFile *  const file,
89                   uint64_t const start,
90                   uint64_t const end,
91                   void *   const buffer,
92                   uint32_t const buffersize,
93                   uint32_t const rate);
94
95 TServer *
96 ConnServer(TConn * const connectionP);
97
98 #endif