2 * Copyright (c) 2010 Frank Lahm
3 * All Rights Reserved. See COPYRIGHT.
8 #endif /* HAVE_CONFIG_H */
10 #include <sys/queue.h>
16 #include <atalk/logger.h>
17 #include <atalk/errchk.h>
18 #include <atalk/locking.h>
19 #include <atalk/adouble.h>
20 #include <atalk/bstrlib.h>
21 #include <atalk/bstradd.h>
23 #include "event2/event-config.h"
24 #include "event2/event.h"
25 #include "event2/http.h"
26 #include "event2/event_compat.h"
27 #include "event2/http_compat.h"
28 #include "event2/rpc.h"
29 #include "event2/rpc_struct.h"
31 #include <atalk/lockrpc.gen.h>
33 #define NUM_RPCS 10000
36 EVRPC_HEADER(lock_msg, lock_req, lock_rep)
37 EVRPC_GENERATE(lock_msg, lock_req, lock_rep)
39 static struct event_base *ev_base;
40 static struct evrpc_pool *rpc_pool;
42 static void ev_log_cb(int severity, const char *msg)
44 LOG(log_warning, logtype_default, (char *)msg);
47 static void do_one_rpc(const char *name);
49 static void msg_rep_cb(struct evrpc_status *status,
56 if (status->error != EVRPC_STATUS_ERR_NONE) {
57 LOG(log_warning, logtype_default, "msg_rep_cb: RPC error: %i", status->error);
58 event_base_loopexit(ev_base, NULL);
63 LOG(log_warning, logtype_default, "msg_rep_cb: count: %i", count);
64 event_base_loopexit(ev_base, NULL);
68 LOG(log_warning, logtype_default, "msg_rep_cb: count: %i", count);
70 snprintf(buf, 32, "count: %i", count);
77 static void do_one_rpc(const char *name)
79 static struct lock *lock = NULL;
80 static struct lock_req *lock_req = NULL;
81 static struct lock_rep *lock_rep = NULL;
85 lock_req = lock_req_new();
86 lock_rep = lock_rep_new();
89 lock_req_clear(lock_req);
90 lock_rep_clear(lock_rep);
93 EVTAG_ASSIGN(lock_req, req_lock, lock);
94 EVTAG_ASSIGN(lock_req, req_filename, name);
96 EVRPC_MAKE_REQUEST(lock_msg, rpc_pool, lock_req, lock_rep, msg_rep_cb, NULL);
99 static int my_rpc_init(const char *addr, unsigned short port)
102 struct evhttp_connection *evcon;
104 EC_NULL_LOG(ev_base = event_init());
105 event_set_log_callback(ev_log_cb);
106 EC_NULL_LOG(rpc_pool = evrpc_pool_new(NULL));
107 EC_NULL_LOG(evcon = evhttp_connection_new(addr, port));
108 evrpc_pool_add_connection(rpc_pool, evcon);
114 int main(int argc, char **argv)
116 set_processname("test");
117 setuplog("default log_maxdebug test.log");
118 if (my_rpc_init("127.0.0.1", 4702) != 0)