Home | History | Annotate | Download | only in librpc

Lines Matching refs:CLIENT

28 struct CLIENT {
30 struct CLIENT *next;
34 /* We insist that there is only one outstanding call for a client at any
36 supporting multiple outstanding RPCs on a client, we will have to
72 static volatile struct CLIENT *clients;
74 /* There's one of these for each RPC client which has received an RPC call. */
77 CLIENT *client = (CLIENT *)__u;
79 (client->xdr->x_prog | 0x01000000),
80 client->xdr->x_vers);
81 pthread_mutex_lock(&client->wait_cb_lock);
82 while (client->cb_stop == 0) {
83 if (!client->got_cb)
84 pthread_cond_wait(&client->wait_cb,
85 &client->wait_cb_lock);
90 if (!client->got_cb) {
92 (client->xdr->x_prog | 0x01000000),
93 client->xdr->x_vers);
96 client->got_cb = 0;
99 * client.
104 ntohl(((uint32 *)(client->xdr->in_msg))[RPC_OFFSET+3]);
106 ntohl(((uint32 *)(client->xdr->in_msg))[RPC_OFFSET+4]);
112 "callback client %08x:%08x.\n",
113 client->xdr->x_prog,
114 client->xdr->x_vers,
115 ntohl(((uint32 *)(client->xdr->in_msg))[RPC_OFFSET]),
116 client->xdr,
118 /* We transplant the xdr of the client into the entry
119 representing the callback client in the list of servers.
120 Note that since we hold the wait_cb_lock for this client,
121 if another call for this callback client arrives before
128 "callback client %08x:%08x!\n",
129 client->xdr->x_prog,
130 client->xdr->x_vers,
136 "callback client %08x:%08x.\n",
137 client->xdr->x_prog,
138 client->xdr->x_vers,
140 *svc_xdr = xdr_clone(client->xdr);
145 client->xdr->in_msg, client->xdr->in_len);
147 client->xdr->out_msg, client->xdr->out_next);
148 (*svc_xdr)->in_len = client->xdr->in_len;
149 (*svc_xdr)->out_next = client->xdr->out_next;
151 pthread_mutex_lock(&client->input_xdr_lock);
153 client->xdr->x_prog, client->xdr->x_vers);
154 client->input_xdr_busy = 0;
155 pthread_cond_signal(&client->input_xdr_wait);
156 pthread_mutex_unlock(&client->input_xdr_lock);
164 client->xdr->x_prog,
165 client->xdr->x_vers,
170 client->xdr->x_prog,
171 client->xdr->x_vers);
175 pthread_mutex_unlock(&client->wait_cb_lock);
179 (client->xdr->x_prog | 0x01000000),
180 client->xdr->x_vers);
201 pthread_mutex_lock(&rx_mutex); /* sync access to the client list */
202 CLIENT *client = (CLIENT *)clients;
203 for (; client; client = client->next) {
204 if (FD_ISSET(client->xdr->fd, &rfds)) {
213 pthread_mutex_lock(&client->input_xdr_lock);
214 while (client->input_xdr_busy) {
217 client->xdr->x_prog, client->xdr->x_vers);
219 &client->input_xdr_wait,
220 &client->input_xdr_lock);
223 client->xdr->x_prog, client->xdr->x_vers);
225 if (client->xdr->xops->read(client->xdr) == 0) {
227 client->xdr->x_prog, client->xdr->x_vers);
230 client->input_xdr_busy = 1;
231 pthread_mutex_unlock(&client->input_xdr_lock);
233 if (((uint32 *)(client->xdr->in_msg))[RPC_OFFSET+1] ==
235 /* Wake up the RPC client to receive its data. */
237 "grabbing mutex to wake up client.\n",
238 client->xdr->x_prog,
239 client->xdr->x_vers,
240 ntohl(((uint32 *)client->xdr->in_msg)[RPC_OFFSET]));
241 pthread_mutex_lock(&client->wait_reply_lock);
242 D("%08x:%08x got mutex, waking up client.\n",
243 client->xdr->x_prog,
244 client->xdr->x_vers);
245 pthread_cond_signal(&client->wait_reply);
246 pthread_mutex_unlock(&client->wait_reply_lock);
251 pthread_mutex_lock(&client->wait_cb_lock);
253 client->xdr->x_prog,
254 client->xdr->x_vers);
255 client->got_cb = 1;
256 if (client->cb_stop < 0) {
258 client->xdr->x_prog,
259 client->xdr->x_vers);
260 client->cb_stop = 0;
261 pthread_create(&client->cb_thread,
263 cb_context, client);
266 client->xdr->x_prog,
267 client->xdr->x_vers);
268 pthread_cond_signal(&client->wait_cb);
269 pthread_mutex_unlock(&client->wait_cb_lock);
279 CLIENT *trav = (CLIENT *)clients;
292 D("RPC-client RX thread exiting!\n");
298 CLIENT * client,
311 xdr_s_type *xdr = client->xdr;
313 pthread_mutex_lock(&client->lock);
330 client->xdr->x_prog,
331 client->xdr->x_vers);
341 client->xdr->x_prog,
342 client->xdr->x_vers);
347 pthread_mutex_lock(&client->wait_reply_lock);
349 client->xdr->x_prog, client->xdr->x_vers, client->xdr->xid);
357 client->xdr->x_prog, client->xdr->x_vers);
358 pthread_cond_wait(&client->wait_reply, &client->wait_reply_lock);
359 D("%08x:%08x received reply.\n", client->xdr->x_prog, client->xdr->x_vers);
364 client->xdr->x_prog, client->xdr->x_vers,
372 client->xdr->x_prog, client->xdr->x_vers);
373 if (!xdr_recv_reply_header (client->xdr, &reply_header)) {
375 client->xdr->x_prog, client->xdr->x_vers);
385 (uint32_t)client->xdr->x_prog, client->xdr->x_vers);
391 (uint32_t)client->xdr->x_prog, client->xdr->x_vers);
400 client->xdr->x_prog, client->xdr->x_vers);
405 client->xdr->x_prog, client->xdr->x_vers);
408 pthread_mutex_lock(&client->input_xdr_lock);
410 client->xdr->x_prog, client->xdr->x_vers);
411 client->input_xdr_busy = 0;
412 pthread_cond_signal(&client->input_xdr_wait);
413 pthread_mutex_unlock(&client->input_xdr_lock);
415 pthread_mutex_unlock(&client->wait_reply_lock);
417 pthread_mutex_unlock(&client->lock);
535 CLIENT *clnt_create(
541 CLIENT *client = calloc(1, sizeof(CLIENT));
542 if (client) {
553 client->xdr = xdr_init_common(name, 1 /* client XDR */);
554 if (!client->xdr) {
555 E("failed to initialize client (permissions?)!\n");
556 free(client);
560 client->xdr->x_prog = prog;
561 client->xdr->x_vers = vers;
562 client->cb_stop = -1; /* callback thread has not been started */
569 FD_SET(client->xdr->fd, &rx_fdset);
570 if (max_rxfd < client->xdr->fd)
571 max_rxfd = client->xdr->fd;
572 client->next = (CLIENT *)clients;
573 clients = client;
579 pthread_mutexattr_init(&client->lock_attr);
580 // pthread_mutexattr_settype(&client->lock_attr, PTHREAD_MUTEX_RECURSIVE);
581 pthread_mutex_init(&client->lock, &client->lock_attr);
582 pthread_mutex_init(&client->wait_reply_lock, &client->lock_attr);
583 pthread_cond_init(&client->wait_reply, NULL);
584 pthread_mutex_init(&client->wait_cb_lock, &client->lock_attr);
585 pthread_cond_init(&client->wait_cb, NULL);
586 pthread_mutex_init(&client->input_xdr_lock, &client->lock_attr);
587 pthread_cond_init(&client->input_xdr_wait, NULL);
592 return client;
595 void clnt_destroy(CLIENT *client) {
596 if (client) {
597 pthread_mutex_lock(&client->lock);
598 D("%08x:%08x destroying client\n",
599 client->xdr->x_prog,
600 client->xdr->x_vers);
603 if (!client->cb_stop) {
605 client->cb_stop = 1;
607 client->xdr->x_prog,
608 client->xdr->x_vers);
609 pthread_mutex_lock(&client->wait_cb_lock);
610 pthread_cond_signal(&client->wait_cb);
611 pthread_mutex_unlock(&client->wait_cb_lock);
613 client->xdr->x_prog,
614 client->xdr->x_vers);
615 pthread_join(client->cb_thread, NULL);
618 pthread_mutex_lock(&rx_mutex); /* sync access to the client list */
620 CLIENT *trav = (CLIENT *)clients, *prev = NULL;
622 if (trav == client) {
623 D("%08x:%08x removing from client list\n",
624 client->xdr->x_prog,
625 client->xdr->x_vers);
631 FD_CLR(client->xdr->fd, &rx_fdset);
642 pthread_mutex_unlock(&rx_mutex); /* sync access to the client list */
644 pthread_mutex_destroy(&client->input_xdr_lock);
645 pthread_cond_destroy(&client->input_xdr_wait);
647 pthread_mutex_destroy(&client->wait_reply_lock);
648 pthread_cond_destroy(&client->wait_reply);
649 xdr_destroy_common(client->xdr);
651 // FIXME: what happens when we lock the client while destroying it,
657 // client (and probably crash), and then we get to the destroy call
659 pthread_mutex_unlock(&client->lock);
660 pthread_mutex_destroy(&client->lock);
661 pthread_mutexattr_destroy(&client->lock_attr);
662 D("client destroy done\n");
663 free(client);