rpc_lib.h

00001 /* 
00002    EyeDB Object Database Management System
00003    Copyright (C) 1994-2008 SYSRA
00004    
00005    EyeDB is free software; you can redistribute it and/or
00006    modify it under the terms of the GNU Lesser General Public
00007    License as published by the Free Software Foundation; either
00008    version 2.1 of the License, or (at your option) any later version.
00009    
00010    EyeDB is distributed in the hope that it will be useful,
00011    but WITHOUT ANY WARRANTY; without even the implied warranty of
00012    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
00013    Lesser General Public License for more details.
00014    
00015    You should have received a copy of the GNU Lesser General Public
00016    License along with this library; if not, write to the Free Software
00017    Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301, USA 
00018 */
00019 
00020 /*
00021    Author: Eric Viara <viara@sysra.com>
00022 */
00023 
00024 
00025 #ifndef _EYEDBLIB_RPC_LIB_H
00026 #define _EYEDBLIB_RPC_LIB_H
00027 
00028 #include <sys/types.h>
00029 #include <sys/socket.h>
00030 #include <sys/uio.h>
00031 #include <sys/un.h>
00032 #include <netdb.h>
00033 #include <netinet/in.h>
00034 #include <unistd.h>
00035 #include <stdlib.h>
00036 
00037 #include <eyedblib/rpc.h>
00038 #include <eyedblib/log.h>
00039 
00040 typedef struct {
00041   eyedblib::uint32 magic;
00042   eyedblib::int32 serial;
00043   rpc_RpcCode code;
00044   int size, ndata;
00045   rpc_Status status;
00046 } rpc_RpcHeader;
00047 
00048 enum {
00049   rpc_SyncData  = 13,
00050   rpc_ASyncData = 18
00051 };
00052 
00053 typedef struct {
00054   int size;
00055   rpc_UserArgFunction func;
00056   rpc_Boolean is_pointer;
00057 } rpc_UserType;
00058 
00059 typedef enum {
00060   rpc_NewConnection = 0x76,
00061   rpc_AssociatedConnection,
00062   rpc_ReplyNewConnection
00063 } rpc_MultiConnCommand;
00064 
00065 typedef struct {
00066   eyedblib::int32 err;
00067   char err_msg[1024];
00068 } rpc_StatusRec;
00069 
00070 typedef struct {
00071   eyedblib::uint32 magic;
00072   rpc_MultiConnCommand cmd;
00073   int xid;
00074 } rpc_MultiConnInfo;
00075   
00076 #define rpc_new(X) (X *)calloc(1, sizeof(X))
00077 
00078 #define rpc_copy(ARG, BUFF, X, SZ, SEND_RCV, FROM_TO) \
00079   do { \
00080   if ((ARG)->send_rcv & SEND_RCV) \
00081     { \
00082       if (FROM_TO == rpc_To) \
00083         memcpy(BUFF, X, SZ); \
00084       else \
00085         memcpy(X, BUFF, SZ); \
00086       BUFF += SZ; \
00087     } \
00088   } while(0)
00089 
00090 #define eyedblib_mcp(D, S, N) \
00091 do { \
00092   int __n__ = (N); \
00093   char *__d__ = (char *)(D), *__s__ = (char *)(S); \
00094   while(__n__--) \
00095     *__d__++ = *__s__++; \
00096 } while(0)
00097 
00098 #define rpc_copy_fast(ARG, BUFF, X, SZ, SEND_RCV, FROM_TO) \
00099 do { \
00100   if ((ARG)->send_rcv & SEND_RCV) \
00101     { \
00102       if ((FROM_TO) == rpc_To) \
00103         eyedblib_mcp(BUFF, X, (SZ)); \
00104       else \
00105         eyedblib_mcp(X, BUFF, (SZ)); \
00106       BUFF += (SZ); \
00107     } \
00108   } while(0)
00109 
00110 #define rpc_copy_fast_xdr(ARG, BUFF, X, SZ, SEND_RCV, FROM_TO, X2H, H2X) \
00111 do { \
00112   if ((ARG)->send_rcv & SEND_RCV) \
00113     { \
00114       if ((FROM_TO) == rpc_To) \
00115         H2X(BUFF, X); \
00116       else \
00117         X2H(X, BUFF); \
00118       BUFF += (SZ); \
00119     } \
00120   } while(0)
00121 
00122 #define rpc_buff_size(COMM_SZ, COMM_BUFF, BUFF) \
00123 (int)((COMM_SZ - 8*sizeof(int)) - (int)((BUFF)-(COMM_BUFF)))
00124 
00125 #define RPC_UTYPS 32
00126 
00127 #define rpc_getUTyp(X, I) (&((X)->utyp[(I) - rpc_NBaseType]))
00128 
00129 /* function prototypes */
00130 extern int
00131 rpc_socketWrite(int, void *, int);
00132 
00133 extern int
00134 rpc_socketRead(int, void *, int);
00135 
00136 extern int
00137 rpc_socketReadTimeout(int, void *, int, int);
00138 
00139 extern int
00140 rpc_hostNameToAddr(const char *, struct in_addr *);
00141 
00142 #define RPC_NDATA 4
00143 
00144 #define RPC_COMM_SIZE 4096
00145 
00146 #define MM(X) ((X) + 0x11111111)
00147 
00148 extern void (*rpc_quit_handler)(void *, int);
00149 extern void *rpc_quit_data;
00150 
00151 extern void rpc_setQuitHandler(void (*_quit_handler)(void *, int), void *_quit_data);
00152 
00153 extern void rpc_getStats(unsigned int *read_cnt,
00154                          unsigned int *read_tm_cnt,
00155                          unsigned int *write_cnt,
00156                          unsigned int *byte_read_cnt,
00157                          unsigned int *byte_write_cnt);
00158 
00159 extern void rpc_socket_nodelay(int s);
00160 extern void h2x_rpc_multiconninfo(rpc_MultiConnInfo *xinfo, rpc_MultiConnInfo *hinfo);
00161 extern void x2h_rpc_multiconninfo(rpc_MultiConnInfo *info);
00162 extern void x2h_rpc_hd(rpc_RpcHeader *rhd);
00163 extern void h2x_rpc_hd(rpc_RpcHeader *xrhd, const rpc_RpcHeader *hrhd);
00164 extern void rpc_setConnFd(int fd);
00165 extern void rpc_checkAFUnixPort(const char *portname);
00166 
00167 /*@@@@ #ifdef LINUX */
00168 #if defined(LINUX) || defined(LINUX64) || defined(LINUX_IA64) || defined(LINUX_PPC64) || defined(ORIGIN) || defined(ALPHA) || defined(AIX) 
00169 #define  _sys_siglistp  _sys_siglist
00170 #endif
00171 
00172 /* 24/09/04: disconnected for test */
00173 /*#define RPC_MIN_SIZE 128*/
00174 
00175 extern void
00176 print_addr(FILE *fd, struct in_addr *addr);
00177 extern int
00178 cmp_addr(const struct in_addr *a1, const struct in_addr *a2);
00179 extern int
00180 hostname2addr(const char *name, struct in_addr *addr);
00181 
00182 extern pid_t rpc_getpid();
00183 
00184 #endif

Generated on Mon Dec 22 18:16:07 2008 for eyedb by  doxygen 1.5.3