2 * Copyright (c) 2004 Teodor Sigaev <teodor@sigaev.ru>
5 * Redistribution and use in source and binary forms, with or without
6 * modification, are permitted provided that the following conditions
8 * 1. Redistributions of source code must retain the above copyright
9 * notice, this list of conditions and the following disclaimer.
10 * 2. Redistributions in binary form must reproduce the above copyright
11 * notice, this list of conditions and the following disclaimer in the
12 * documentation and/or other materials provided with the distribution.
13 * 3. Neither the name of the author nor the names of any co-contributors
14 * may be used to endorse or promote products derived from this software
15 * without specific prior written permission.
17 * THIS SOFTWARE IS PROVIDED BY CONTRIBUTORS ``AS IS'' AND ANY EXPRESS
18 * OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
19 * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
20 * ARE DISCLAIMED. IN NO EVENT SHALL CONTRIBUTORS BE LIABLE FOR ANY
21 * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
22 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE
23 * GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
24 * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER
25 * IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR
26 * OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN
27 * IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
30 #ifndef __CONNECTION_H__
31 #define __CONNECTION_H__
33 #include <sys/types.h>
35 #include <sys/socket.h>
36 #include <netinet/in.h>
37 #include <arpa/inet.h>
42 #define CS_INPROCESS 1
43 #define CS_CONNECTED 2
48 #define CS_FINISHSEND 7
49 #define CS_FINISHREAD 8
52 #define CS_NOTINITED 11
57 #define READ_INCRIMENT_BUFSIZ 1024
70 struct sockaddr_in serv_addr;
76 #define TCCONNHDRSZ ( sizeof(TC_Connection) - sizeof(void*) )
78 TC_Connection *TC_fillConnection( TC_Connection *cs, char *name, u_int32_t port );
79 TC_Connection* TC_AcceptTcp(TC_Connection *cs);
80 u_int32_t TC_ClientInitConnection(TC_Connection *cs, char *name, u_int32_t port);
81 u_int32_t TC_ServerInitConnect( TC_Connection *cs );
82 u_int32_t TC_ServerConnect( TC_Connection *cs, int timeout );
83 u_int32_t TC_Send( TC_Connection *cs );
84 u_int32_t TC_Read( TC_Connection *cs );
85 u_int32_t TC_Talk( TC_Connection *cs );
86 void TC_FreeConnection( TC_Connection *cs );
87 int TC_ReadyIO( TC_Connection **cs, int number, int timeout );
95 #define TCMSGHDRSZ (2*sizeof(u_int32_t))
104 /* private members */
106 struct sockaddr_in host_addr;
111 * TC_Connection conn,*connptr;
112 * conn.fd = TC_AcceptUdp("127.0.0.1", 5432);
113 * conn.state = CS_READ;
116 * if ( TC_ReadyIO( &connptr, 1, 100 ) ) {
118 * if ( TC_getMsg(conn.fd, &m) == CS_OK ) {
127 * msg.host = "127.0.0.1";
130 * msg.msg = GOTFILLEDPMSG();
131 * if ( TC_sendMsg(&msg)!=CS_OK ) {
134 * msg.msg = GOTFILLEDPMSG();
135 * if ( TC_sendMsg(&msg)!=CS_OK ) {
141 int TC_AcceptUdp(char *host, int port);
142 u_int32_t TC_getMsg( int sockfd, Msg *msg );
143 u_int32_t TC_sendMsg( Msg *msg );
144 void TC_closefd( Msg *msg );
149 TC_Connection **conn;
152 void TC_addConnection(PoolConnection *pool, TC_Connection *c);
153 void TC_deleteConnectionByN(PoolConnection *pool, int n);
154 void TC_deleteConnectionByC(PoolConnection *pool, TC_Connection *c);