00001
00002
00003
00004
00005
00006
00007
00008
00009
00010 #ifndef _EX_REPQUOTE_H_
00011 #define _EX_REPQUOTE_H_
00012
00013 #define SELF_EID 1
00014
00015 typedef struct {
00016 char *host;
00017 u_int32_t port;
00018 } repsite_t;
00019
00020
00021 extern int master_eid;
00022 extern char *myaddr;
00023 extern unsigned short myport;
00024
00025 struct __member; typedef struct __member member_t;
00026 struct __machtab; typedef struct __machtab machtab_t;
00027
00028
00029 typedef struct {
00030 DB_ENV *dbenv;
00031 const char *progname;
00032 const char *home;
00033 machtab_t *machtab;
00034 repsite_t *sites;
00035 int nsites;
00036 } all_args;
00037
00038
00039 typedef struct {
00040 DB_ENV *dbenv;
00041 const char * home;
00042 const char * progname;
00043 machtab_t *machtab;
00044 int port;
00045 } connect_args;
00046
00047 #define CACHESIZE (10 * 1024 * 1024)
00048 #define DATABASE "quote.db"
00049 #define MAX_THREADS 25
00050 #define SLEEPTIME 3
00051
00052 #ifndef COMPQUIET
00053 #define COMPQUIET(x,y) x = (y)
00054 #endif
00055
00056
00057 #ifdef _WIN32
00058
00059 #include <winsock2.h>
00060 #include <windows.h>
00061
00062 extern int getopt(int, char * const *, const char *);
00063
00064 typedef HANDLE thread_t;
00065 #define thread_create(thrp, attr, func, arg) \
00066 (((*(thrp) = CreateThread(NULL, 0, \
00067 (LPTHREAD_START_ROUTINE)(func), (arg), 0, NULL)) == NULL) ? -1 : 0)
00068 #define thread_join(thr, statusp) \
00069 ((WaitForSingleObject((thr), INFINITE) == WAIT_OBJECT_0) && \
00070 GetExitCodeThread((thr), (LPDWORD)(statusp)) ? 0 : -1)
00071
00072 typedef HANDLE mutex_t;
00073 #define mutex_init(m, attr) \
00074 (((*(m) = CreateMutex(NULL, FALSE, NULL)) != NULL) ? 0 : -1)
00075 #define mutex_lock(m) \
00076 ((WaitForSingleObject(*(m), INFINITE) == WAIT_OBJECT_0) ? 0 : -1)
00077 #define mutex_unlock(m) (ReleaseMutex(*(m)) ? 0 : -1)
00078 #define sleep(s) Sleep(1000 * (s))
00079
00080 typedef SOCKET socket_t;
00081 #define SOCKET_CREATION_FAILURE INVALID_SOCKET
00082 #define readsocket(s, buf, sz) recv((s), (buf), (int)(sz), 0)
00083 #define writesocket(s, buf, sz) send((s), (const char *)(buf), (int)(sz), 0)
00084 #define net_errno WSAGetLastError()
00085
00086 #else
00087
00088 #include <netinet/in.h>
00089 #include <sys/socket.h>
00090 #include <sys/wait.h>
00091 #include <netdb.h>
00092 #include <pthread.h>
00093 #include <signal.h>
00094 #include <unistd.h>
00095
00096 typedef pthread_t thread_t;
00097 #define thread_create(thrp, attr, func, arg) \
00098 pthread_create((thrp), (attr), (func), (arg))
00099 #define thread_join(thr, statusp) pthread_join((thr), (statusp))
00100
00101 typedef pthread_mutex_t mutex_t;
00102 #define mutex_init(m, attr) pthread_mutex_init((m), (attr))
00103 #define mutex_lock(m) pthread_mutex_lock(m)
00104 #define mutex_unlock(m) pthread_mutex_unlock(m)
00105
00106 typedef int socket_t;
00107 #define SOCKET_CREATION_FAILURE -1
00108 #define closesocket(fd) close(fd)
00109 #define net_errno errno
00110 #define readsocket(s, buf, sz) read((s), (buf), (sz))
00111 #define writesocket(s, buf, sz) write((s), (buf), (sz))
00112
00113 #endif
00114
00115 void *connect_all __P((void *args));
00116 void *connect_thread __P((void *args));
00117 int doclient __P((DB_ENV *, const char *, machtab_t *));
00118 int domaster __P((DB_ENV *, const char *));
00119 socket_t get_accepted_socket __P((const char *, int));
00120 socket_t get_connected_socket
00121 __P((machtab_t *, const char *, const char *, int, int *, int *));
00122 int get_next_message __P((socket_t, DBT *, DBT *));
00123 socket_t listen_socket_init __P((const char *, int));
00124 socket_t listen_socket_accept __P((machtab_t *, const char *, socket_t, int *));
00125 int machtab_getinfo __P((machtab_t *, int, u_int32_t *, int *));
00126 int machtab_init __P((machtab_t **, int, int));
00127 void machtab_parm __P((machtab_t *, int *, int *, u_int32_t *));
00128 int machtab_rem __P((machtab_t *, int, int));
00129 int quote_send __P((DB_ENV *, const DBT *, const DBT *, const DB_LSN *,
00130 int, u_int32_t));
00131
00132 #endif