svc_vc.c (95658) | svc_vc.c (109359) |
---|---|
1/* $NetBSD: svc_vc.c,v 1.7 2000/08/03 00:01:53 fvdl Exp $ */ 2 3/* 4 * Sun RPC is a product of Sun Microsystems, Inc. and is provided for 5 * unrestricted use provided that this legend is included on all tape 6 * media and as a part of the software program in whole or part. Users 7 * may copy or modify Sun RPC without charge, but are not authorized 8 * to license or distribute it to anyone else except as part of a product or --- 20 unchanged lines hidden (view full) --- 29 * Mountain View, California 94043 30 */ 31 32#if defined(LIBC_SCCS) && !defined(lint) 33static char *sccsid = "@(#)svc_tcp.c 1.21 87/08/11 Copyr 1984 Sun Micro"; 34static char *sccsid = "@(#)svc_tcp.c 2.2 88/08/01 4.0 RPCSRC"; 35#endif 36#include <sys/cdefs.h> | 1/* $NetBSD: svc_vc.c,v 1.7 2000/08/03 00:01:53 fvdl Exp $ */ 2 3/* 4 * Sun RPC is a product of Sun Microsystems, Inc. and is provided for 5 * unrestricted use provided that this legend is included on all tape 6 * media and as a part of the software program in whole or part. Users 7 * may copy or modify Sun RPC without charge, but are not authorized 8 * to license or distribute it to anyone else except as part of a product or --- 20 unchanged lines hidden (view full) --- 29 * Mountain View, California 94043 30 */ 31 32#if defined(LIBC_SCCS) && !defined(lint) 33static char *sccsid = "@(#)svc_tcp.c 1.21 87/08/11 Copyr 1984 Sun Micro"; 34static char *sccsid = "@(#)svc_tcp.c 2.2 88/08/01 4.0 RPCSRC"; 35#endif 36#include <sys/cdefs.h> |
37__FBSDID("$FreeBSD: head/lib/libc/rpc/svc_vc.c 95658 2002-04-28 15:18:50Z des $"); | 37__FBSDID("$FreeBSD: head/lib/libc/rpc/svc_vc.c 109359 2003-01-16 07:13:51Z mbr $"); |
38 39/* 40 * svc_vc.c, Server side for Connection Oriented based RPC. 41 * 42 * Actually implements two flavors of transporter - 43 * a tcp rendezvouser (a listner and connection establisher) 44 * and a record/tcp stream. 45 */ 46 47#include "namespace.h" 48#include "reentrant.h" 49#include <sys/types.h> 50#include <sys/param.h> 51#include <sys/poll.h> 52#include <sys/socket.h> 53#include <sys/un.h> | 38 39/* 40 * svc_vc.c, Server side for Connection Oriented based RPC. 41 * 42 * Actually implements two flavors of transporter - 43 * a tcp rendezvouser (a listner and connection establisher) 44 * and a record/tcp stream. 45 */ 46 47#include "namespace.h" 48#include "reentrant.h" 49#include <sys/types.h> 50#include <sys/param.h> 51#include <sys/poll.h> 52#include <sys/socket.h> 53#include <sys/un.h> |
54#include <sys/time.h> |
|
54#include <sys/uio.h> 55#include <netinet/in.h> 56#include <netinet/tcp.h> 57 58#include <assert.h> 59#include <err.h> 60#include <errno.h> | 55#include <sys/uio.h> 56#include <netinet/in.h> 57#include <netinet/tcp.h> 58 59#include <assert.h> 60#include <err.h> 61#include <errno.h> |
62#include <fcntl.h> |
|
61#include <stdio.h> 62#include <stdlib.h> 63#include <string.h> 64#include <unistd.h> 65 66#include <rpc/rpc.h> 67 68#include "rpc_com.h" 69#include "un-namespace.h" 70 71struct cmessage { 72 struct cmsghdr cmsg; 73 struct cmsgcred cmcred; 74}; 75 | 63#include <stdio.h> 64#include <stdlib.h> 65#include <string.h> 66#include <unistd.h> 67 68#include <rpc/rpc.h> 69 70#include "rpc_com.h" 71#include "un-namespace.h" 72 73struct cmessage { 74 struct cmsghdr cmsg; 75 struct cmsgcred cmcred; 76}; 77 |
78extern rwlock_t svc_fd_lock; 79 |
|
76static SVCXPRT *makefd_xprt(int, u_int, u_int); 77static bool_t rendezvous_request(SVCXPRT *, struct rpc_msg *); 78static enum xprt_stat rendezvous_stat(SVCXPRT *); 79static void svc_vc_destroy(SVCXPRT *); | 80static SVCXPRT *makefd_xprt(int, u_int, u_int); 81static bool_t rendezvous_request(SVCXPRT *, struct rpc_msg *); 82static enum xprt_stat rendezvous_stat(SVCXPRT *); 83static void svc_vc_destroy(SVCXPRT *); |
84static void __svc_vc_dodestroy (SVCXPRT *); |
|
80static int read_vc(void *, void *, int); 81static int write_vc(void *, void *, int); 82static enum xprt_stat svc_vc_stat(SVCXPRT *); 83static bool_t svc_vc_recv(SVCXPRT *, struct rpc_msg *); 84static bool_t svc_vc_getargs(SVCXPRT *, xdrproc_t, void *); 85static bool_t svc_vc_freeargs(SVCXPRT *, xdrproc_t, void *); 86static bool_t svc_vc_reply(SVCXPRT *, struct rpc_msg *); 87static void svc_vc_rendezvous_ops(SVCXPRT *); 88static void svc_vc_ops(SVCXPRT *); 89static bool_t svc_vc_control(SVCXPRT *xprt, const u_int rq, void *in); | 85static int read_vc(void *, void *, int); 86static int write_vc(void *, void *, int); 87static enum xprt_stat svc_vc_stat(SVCXPRT *); 88static bool_t svc_vc_recv(SVCXPRT *, struct rpc_msg *); 89static bool_t svc_vc_getargs(SVCXPRT *, xdrproc_t, void *); 90static bool_t svc_vc_freeargs(SVCXPRT *, xdrproc_t, void *); 91static bool_t svc_vc_reply(SVCXPRT *, struct rpc_msg *); 92static void svc_vc_rendezvous_ops(SVCXPRT *); 93static void svc_vc_ops(SVCXPRT *); 94static bool_t svc_vc_control(SVCXPRT *xprt, const u_int rq, void *in); |
95static bool_t svc_vc_rendezvous_control (SVCXPRT *xprt, const u_int rq, 96 void *in); |
|
90static int __msgread_withcred(int, void *, size_t, struct cmessage *); 91static int __msgwrite(int, void *, size_t); 92 93struct cf_rendezvous { /* kept in xprt->xp_p1 for rendezvouser */ 94 u_int sendsize; 95 u_int recvsize; | 97static int __msgread_withcred(int, void *, size_t, struct cmessage *); 98static int __msgwrite(int, void *, size_t); 99 100struct cf_rendezvous { /* kept in xprt->xp_p1 for rendezvouser */ 101 u_int sendsize; 102 u_int recvsize; |
103 int maxrec; |
|
96}; 97 98struct cf_conn { /* kept in xprt->xp_p1 for actual connection */ 99 enum xprt_stat strm_stat; 100 u_int32_t x_id; 101 XDR xdrs; 102 char verf_body[MAX_AUTH_BYTES]; | 104}; 105 106struct cf_conn { /* kept in xprt->xp_p1 for actual connection */ 107 enum xprt_stat strm_stat; 108 u_int32_t x_id; 109 XDR xdrs; 110 char verf_body[MAX_AUTH_BYTES]; |
111 u_int sendsize; 112 u_int recvsize; 113 int maxrec; 114 bool_t nonblock; 115 struct timeval last_recv_time; |
|
103}; 104 105/* 106 * Usage: 107 * xprt = svc_vc_create(sock, send_buf_size, recv_buf_size); 108 * 109 * Creates, registers, and returns a (rpc) tcp based transporter. 110 * Once *xprt is initialized, it is registered as a transporter --- 23 unchanged lines hidden (view full) --- 134 if (r == NULL) { 135 warnx("svc_vc_create: out of memory"); 136 goto cleanup_svc_vc_create; 137 } 138 if (!__rpc_fd2sockinfo(fd, &si)) 139 return NULL; 140 r->sendsize = __rpc_get_t_size(si.si_af, si.si_proto, (int)sendsize); 141 r->recvsize = __rpc_get_t_size(si.si_af, si.si_proto, (int)recvsize); | 116}; 117 118/* 119 * Usage: 120 * xprt = svc_vc_create(sock, send_buf_size, recv_buf_size); 121 * 122 * Creates, registers, and returns a (rpc) tcp based transporter. 123 * Once *xprt is initialized, it is registered as a transporter --- 23 unchanged lines hidden (view full) --- 147 if (r == NULL) { 148 warnx("svc_vc_create: out of memory"); 149 goto cleanup_svc_vc_create; 150 } 151 if (!__rpc_fd2sockinfo(fd, &si)) 152 return NULL; 153 r->sendsize = __rpc_get_t_size(si.si_af, si.si_proto, (int)sendsize); 154 r->recvsize = __rpc_get_t_size(si.si_af, si.si_proto, (int)recvsize); |
155 r->maxrec = __svc_maxrec; |
|
142 xprt = mem_alloc(sizeof(SVCXPRT)); 143 if (xprt == NULL) { 144 warnx("svc_vc_create: out of memory"); 145 goto cleanup_svc_vc_create; 146 } 147 xprt->xp_tp = NULL; 148 xprt->xp_p1 = r; 149 xprt->xp_p2 = NULL; --- 130 unchanged lines hidden (view full) --- 280} 281 282/*ARGSUSED*/ 283static bool_t 284rendezvous_request(xprt, msg) 285 SVCXPRT *xprt; 286 struct rpc_msg *msg; 287{ | 156 xprt = mem_alloc(sizeof(SVCXPRT)); 157 if (xprt == NULL) { 158 warnx("svc_vc_create: out of memory"); 159 goto cleanup_svc_vc_create; 160 } 161 xprt->xp_tp = NULL; 162 xprt->xp_p1 = r; 163 xprt->xp_p2 = NULL; --- 130 unchanged lines hidden (view full) --- 294} 295 296/*ARGSUSED*/ 297static bool_t 298rendezvous_request(xprt, msg) 299 SVCXPRT *xprt; 300 struct rpc_msg *msg; 301{ |
288 int sock; | 302 int sock, flags; |
289 struct cf_rendezvous *r; | 303 struct cf_rendezvous *r; |
304 struct cf_conn *cd; |
|
290 struct sockaddr_storage addr; 291 socklen_t len; 292 struct __rpc_sockinfo si; | 305 struct sockaddr_storage addr; 306 socklen_t len; 307 struct __rpc_sockinfo si; |
308 SVCXPRT *newxprt; 309 fd_set cleanfds; |
|
293 294 assert(xprt != NULL); 295 assert(msg != NULL); 296 297 r = (struct cf_rendezvous *)xprt->xp_p1; 298again: 299 len = sizeof addr; 300 if ((sock = _accept(xprt->xp_fd, (struct sockaddr *)(void *)&addr, 301 &len)) < 0) { 302 if (errno == EINTR) 303 goto again; | 310 311 assert(xprt != NULL); 312 assert(msg != NULL); 313 314 r = (struct cf_rendezvous *)xprt->xp_p1; 315again: 316 len = sizeof addr; 317 if ((sock = _accept(xprt->xp_fd, (struct sockaddr *)(void *)&addr, 318 &len)) < 0) { 319 if (errno == EINTR) 320 goto again; |
304 return (FALSE); | 321 /* 322 * Clean out the most idle file descriptor when we're 323 * running out. 324 */ 325 if (errno == EMFILE || errno == ENFILE) { 326 cleanfds = svc_fdset; 327 __svc_clean_idle(&cleanfds, 0, FALSE); 328 goto again; 329 } 330 return (FALSE); |
305 } 306 /* 307 * make a new transporter (re-uses xprt) 308 */ | 331 } 332 /* 333 * make a new transporter (re-uses xprt) 334 */ |
309 xprt = makefd_xprt(sock, r->sendsize, r->recvsize); 310 xprt->xp_rtaddr.buf = mem_alloc(len); 311 if (xprt->xp_rtaddr.buf == NULL) | 335 newxprt = makefd_xprt(sock, r->sendsize, r->recvsize); 336 newxprt->xp_rtaddr.buf = mem_alloc(len); 337 if (newxprt->xp_rtaddr.buf == NULL) |
312 return (FALSE); | 338 return (FALSE); |
313 memcpy(xprt->xp_rtaddr.buf, &addr, len); 314 xprt->xp_rtaddr.len = len; | 339 memcpy(newxprt->xp_rtaddr.buf, &addr, len); 340 newxprt->xp_rtaddr.len = len; |
315#ifdef PORTMAP 316 if (addr.ss_family == AF_INET || addr.ss_family == AF_LOCAL) { | 341#ifdef PORTMAP 342 if (addr.ss_family == AF_INET || addr.ss_family == AF_LOCAL) { |
317 xprt->xp_raddr = *(struct sockaddr_in *)xprt->xp_rtaddr.buf; 318 xprt->xp_addrlen = sizeof (struct sockaddr_in); | 343 newxprt->xp_raddr = *(struct sockaddr_in *)newxprt->xp_rtaddr.buf; 344 newxprt->xp_addrlen = sizeof (struct sockaddr_in); |
319 } 320#endif /* PORTMAP */ 321 if (__rpc_fd2sockinfo(sock, &si) && si.si_proto == IPPROTO_TCP) { 322 len = 1; 323 /* XXX fvdl - is this useful? */ 324 _setsockopt(sock, IPPROTO_TCP, TCP_NODELAY, &len, sizeof (len)); 325 } | 345 } 346#endif /* PORTMAP */ 347 if (__rpc_fd2sockinfo(sock, &si) && si.si_proto == IPPROTO_TCP) { 348 len = 1; 349 /* XXX fvdl - is this useful? */ 350 _setsockopt(sock, IPPROTO_TCP, TCP_NODELAY, &len, sizeof (len)); 351 } |
352 353 cd = (struct cf_conn *)newxprt->xp_p1; 354 355 cd->recvsize = r->recvsize; 356 cd->sendsize = r->sendsize; 357 cd->maxrec = r->maxrec; 358 359 if (cd->maxrec != 0) { 360 flags = fcntl(sock, F_GETFL, 0); 361 if (flags == -1) 362 return (FALSE); 363 if (fcntl(sock, F_SETFL, flags | O_NONBLOCK) == -1) 364 return (FALSE); 365 if (cd->recvsize > cd->maxrec) 366 cd->recvsize = cd->maxrec; 367 cd->nonblock = TRUE; 368 __xdrrec_setnonblock(&cd->xdrs, cd->maxrec); 369 } else 370 cd->nonblock = FALSE; 371 372 gettimeofday(&cd->last_recv_time, NULL); 373 |
|
326 return (FALSE); /* there is never an rpc msg to be processed */ 327} 328 329/*ARGSUSED*/ 330static enum xprt_stat 331rendezvous_stat(xprt) 332 SVCXPRT *xprt; 333{ 334 335 return (XPRT_IDLE); 336} 337 338static void 339svc_vc_destroy(xprt) 340 SVCXPRT *xprt; 341{ | 374 return (FALSE); /* there is never an rpc msg to be processed */ 375} 376 377/*ARGSUSED*/ 378static enum xprt_stat 379rendezvous_stat(xprt) 380 SVCXPRT *xprt; 381{ 382 383 return (XPRT_IDLE); 384} 385 386static void 387svc_vc_destroy(xprt) 388 SVCXPRT *xprt; 389{ |
390 assert(xprt != NULL); 391 392 xprt_unregister(xprt); 393 __svc_vc_dodestroy(xprt); 394} 395 396static void 397__svc_vc_dodestroy(xprt) 398 SVCXPRT *xprt; 399{ |
|
342 struct cf_conn *cd; 343 struct cf_rendezvous *r; 344 | 400 struct cf_conn *cd; 401 struct cf_rendezvous *r; 402 |
345 assert(xprt != NULL); 346 | |
347 cd = (struct cf_conn *)xprt->xp_p1; 348 | 403 cd = (struct cf_conn *)xprt->xp_p1; 404 |
349 xprt_unregister(xprt); | |
350 if (xprt->xp_fd != RPC_ANYFD) 351 (void)_close(xprt->xp_fd); 352 if (xprt->xp_port != 0) { 353 /* a rendezvouser socket */ 354 r = (struct cf_rendezvous *)xprt->xp_p1; 355 mem_free(r, sizeof (struct cf_rendezvous)); 356 xprt->xp_port = 0; 357 } else { --- 17 unchanged lines hidden (view full) --- 375svc_vc_control(xprt, rq, in) 376 SVCXPRT *xprt; 377 const u_int rq; 378 void *in; 379{ 380 return (FALSE); 381} 382 | 405 if (xprt->xp_fd != RPC_ANYFD) 406 (void)_close(xprt->xp_fd); 407 if (xprt->xp_port != 0) { 408 /* a rendezvouser socket */ 409 r = (struct cf_rendezvous *)xprt->xp_p1; 410 mem_free(r, sizeof (struct cf_rendezvous)); 411 xprt->xp_port = 0; 412 } else { --- 17 unchanged lines hidden (view full) --- 430svc_vc_control(xprt, rq, in) 431 SVCXPRT *xprt; 432 const u_int rq; 433 void *in; 434{ 435 return (FALSE); 436} 437 |
438static bool_t 439svc_vc_rendezvous_control(xprt, rq, in) 440 SVCXPRT *xprt; 441 const u_int rq; 442 void *in; 443{ 444 struct cf_rendezvous *cfp; 445 446 cfp = (struct cf_rendezvous *)xprt->xp_p1; 447 if (cfp == NULL) 448 return (FALSE); 449 switch (rq) { 450 case SVCGET_CONNMAXREC: 451 *(int *)in = cfp->maxrec; 452 break; 453 case SVCSET_CONNMAXREC: 454 cfp->maxrec = *(int *)in; 455 break; 456 default: 457 return (FALSE); 458 } 459 return (TRUE); 460} 461 |
|
383/* 384 * reads data from the tcp or uip connection. 385 * any error is fatal and the connection is closed. 386 * (And a read of zero bytes is a half closed stream => error.) 387 * All read operations timeout after 35 seconds. A timeout is 388 * fatal for the connection. 389 */ 390static int 391read_vc(xprtp, buf, len) 392 void *xprtp; 393 void *buf; 394 int len; 395{ 396 SVCXPRT *xprt; 397 int sock; 398 int milliseconds = 35 * 1000; 399 struct pollfd pollfd; 400 struct sockaddr *sa; 401 struct cmessage *cm; | 462/* 463 * reads data from the tcp or uip connection. 464 * any error is fatal and the connection is closed. 465 * (And a read of zero bytes is a half closed stream => error.) 466 * All read operations timeout after 35 seconds. A timeout is 467 * fatal for the connection. 468 */ 469static int 470read_vc(xprtp, buf, len) 471 void *xprtp; 472 void *buf; 473 int len; 474{ 475 SVCXPRT *xprt; 476 int sock; 477 int milliseconds = 35 * 1000; 478 struct pollfd pollfd; 479 struct sockaddr *sa; 480 struct cmessage *cm; |
481 struct cf_conn *cfp; |
|
402 403 xprt = (SVCXPRT *)xprtp; 404 assert(xprt != NULL); 405 406 sock = xprt->xp_fd; 407 | 482 483 xprt = (SVCXPRT *)xprtp; 484 assert(xprt != NULL); 485 486 sock = xprt->xp_fd; 487 |
488 cfp = (struct cf_conn *)xprt->xp_p1; 489 490 if (cfp->nonblock) { 491 len = read(sock, buf, (size_t)len); 492 if (len < 0) { 493 if (errno == EAGAIN) 494 len = 0; 495 else 496 goto fatal_err; 497 } 498 if (len != 0) 499 gettimeofday(&cfp->last_recv_time, NULL); 500 return len; 501 } 502 |
|
408 do { 409 pollfd.fd = sock; 410 pollfd.events = POLLIN; 411 pollfd.revents = 0; 412 switch (_poll(&pollfd, 1, milliseconds)) { 413 case -1: 414 if (errno == EINTR) 415 continue; --- 11 unchanged lines hidden (view full) --- 427 if (sa->sa_family == AF_LOCAL) { 428 cm = (struct cmessage *)xprt->xp_verf.oa_base; 429 if ((len = __msgread_withcred(sock, buf, len, cm)) > 0) { 430 xprt->xp_p2 = &cm->cmcred; 431 return (len); 432 } else 433 goto fatal_err; 434 } else { | 503 do { 504 pollfd.fd = sock; 505 pollfd.events = POLLIN; 506 pollfd.revents = 0; 507 switch (_poll(&pollfd, 1, milliseconds)) { 508 case -1: 509 if (errno == EINTR) 510 continue; --- 11 unchanged lines hidden (view full) --- 522 if (sa->sa_family == AF_LOCAL) { 523 cm = (struct cmessage *)xprt->xp_verf.oa_base; 524 if ((len = __msgread_withcred(sock, buf, len, cm)) > 0) { 525 xprt->xp_p2 = &cm->cmcred; 526 return (len); 527 } else 528 goto fatal_err; 529 } else { |
435 if ((len = _read(sock, buf, (size_t)len)) > 0) | 530 if ((len = read(sock, buf, (size_t)len)) > 0) { 531 gettimeofday(&cfp->last_recv_time, NULL); |
436 return (len); | 532 return (len); |
533 } |
|
437 } 438 439fatal_err: 440 ((struct cf_conn *)(xprt->xp_p1))->strm_stat = XPRT_DIED; 441 return (-1); 442} 443 444/* --- 4 unchanged lines hidden (view full) --- 449write_vc(xprtp, buf, len) 450 void *xprtp; 451 void *buf; 452 int len; 453{ 454 SVCXPRT *xprt; 455 int i, cnt; 456 struct sockaddr *sa; | 534 } 535 536fatal_err: 537 ((struct cf_conn *)(xprt->xp_p1))->strm_stat = XPRT_DIED; 538 return (-1); 539} 540 541/* --- 4 unchanged lines hidden (view full) --- 546write_vc(xprtp, buf, len) 547 void *xprtp; 548 void *buf; 549 int len; 550{ 551 SVCXPRT *xprt; 552 int i, cnt; 553 struct sockaddr *sa; |
554 struct cf_conn *cd; 555 struct timeval tv0, tv1; |
|
457 458 xprt = (SVCXPRT *)xprtp; 459 assert(xprt != NULL); | 556 557 xprt = (SVCXPRT *)xprtp; 558 assert(xprt != NULL); |
559 560 cd = (struct cf_conn *)xprt->xp_p1; 561 562 if (cd->nonblock) 563 gettimeofday(&tv0, NULL); |
|
460 461 sa = (struct sockaddr *)xprt->xp_rtaddr.buf; | 564 565 sa = (struct sockaddr *)xprt->xp_rtaddr.buf; |
462 if (sa->sa_family == AF_LOCAL) { 463 for (cnt = len; cnt > 0; cnt -= i, buf += i) { 464 if ((i = __msgwrite(xprt->xp_fd, buf, 465 (size_t)cnt)) < 0) { 466 ((struct cf_conn *)(xprt->xp_p1))->strm_stat = 467 XPRT_DIED; | 566 for (cnt = len; cnt > 0; cnt -= i, buf += i) { 567 if (sa->sa_family == AF_LOCAL) 568 i = __msgwrite(xprt->xp_fd, buf, (size_t)cnt); 569 else 570 i = _write(xprt->xp_fd, buf, (size_t)cnt); 571 if (i < 0) { 572 if (errno != EAGAIN || !cd->nonblock) { 573 cd->strm_stat = XPRT_DIED; |
468 return (-1); 469 } | 574 return (-1); 575 } |
470 } 471 } else { 472 for (cnt = len; cnt > 0; cnt -= i, buf += i) { 473 if ((i = _write(xprt->xp_fd, buf, 474 (size_t)cnt)) < 0) { 475 ((struct cf_conn *)(xprt->xp_p1))->strm_stat = 476 XPRT_DIED; 477 return (-1); | 576 if (cd->nonblock && i != cnt) { 577 /* 578 * For non-blocking connections, do not 579 * take more than 2 seconds writing the 580 * data out. 581 * 582 * XXX 2 is an arbitrary amount. 583 */ 584 gettimeofday(&tv1, NULL); 585 if (tv1.tv_sec - tv0.tv_sec >= 2) { 586 cd->strm_stat = XPRT_DIED; 587 return (-1); 588 } |
478 } 479 } 480 } 481 482 return (len); 483} 484 485static enum xprt_stat --- 22 unchanged lines hidden (view full) --- 508 XDR *xdrs; 509 510 assert(xprt != NULL); 511 assert(msg != NULL); 512 513 cd = (struct cf_conn *)(xprt->xp_p1); 514 xdrs = &(cd->xdrs); 515 | 589 } 590 } 591 } 592 593 return (len); 594} 595 596static enum xprt_stat --- 22 unchanged lines hidden (view full) --- 619 XDR *xdrs; 620 621 assert(xprt != NULL); 622 assert(msg != NULL); 623 624 cd = (struct cf_conn *)(xprt->xp_p1); 625 xdrs = &(cd->xdrs); 626 |
627 if (cd->nonblock) { 628 if (!__xdrrec_getrec(xdrs, &cd->strm_stat, TRUE)) 629 return FALSE; 630 } 631 |
|
516 xdrs->x_op = XDR_DECODE; 517 (void)xdrrec_skiprecord(xdrs); 518 if (xdr_callmsg(xdrs, msg)) { 519 cd->x_id = msg->rm_xid; 520 return (TRUE); 521 } 522 cd->strm_stat = XPRT_DIED; 523 return (FALSE); --- 31 unchanged lines hidden (view full) --- 555 556static bool_t 557svc_vc_reply(xprt, msg) 558 SVCXPRT *xprt; 559 struct rpc_msg *msg; 560{ 561 struct cf_conn *cd; 562 XDR *xdrs; | 632 xdrs->x_op = XDR_DECODE; 633 (void)xdrrec_skiprecord(xdrs); 634 if (xdr_callmsg(xdrs, msg)) { 635 cd->x_id = msg->rm_xid; 636 return (TRUE); 637 } 638 cd->strm_stat = XPRT_DIED; 639 return (FALSE); --- 31 unchanged lines hidden (view full) --- 671 672static bool_t 673svc_vc_reply(xprt, msg) 674 SVCXPRT *xprt; 675 struct rpc_msg *msg; 676{ 677 struct cf_conn *cd; 678 XDR *xdrs; |
563 bool_t stat; | 679 bool_t rstat; |
564 565 assert(xprt != NULL); 566 assert(msg != NULL); 567 568 cd = (struct cf_conn *)(xprt->xp_p1); 569 xdrs = &(cd->xdrs); 570 571 xdrs->x_op = XDR_ENCODE; 572 msg->rm_xid = cd->x_id; | 680 681 assert(xprt != NULL); 682 assert(msg != NULL); 683 684 cd = (struct cf_conn *)(xprt->xp_p1); 685 xdrs = &(cd->xdrs); 686 687 xdrs->x_op = XDR_ENCODE; 688 msg->rm_xid = cd->x_id; |
573 stat = xdr_replymsg(xdrs, msg); | 689 rstat = xdr_replymsg(xdrs, msg); |
574 (void)xdrrec_endofrecord(xdrs, TRUE); | 690 (void)xdrrec_endofrecord(xdrs, TRUE); |
575 return (stat); | 691 return (rstat); |
576} 577 578static void 579svc_vc_ops(xprt) 580 SVCXPRT *xprt; 581{ 582 static struct xp_ops ops; 583 static struct xp_ops2 ops2; --- 30 unchanged lines hidden (view full) --- 614 ops.xp_stat = rendezvous_stat; 615 ops.xp_getargs = 616 (bool_t (*)(SVCXPRT *, xdrproc_t, void *))abort; 617 ops.xp_reply = 618 (bool_t (*)(SVCXPRT *, struct rpc_msg *))abort; 619 ops.xp_freeargs = 620 (bool_t (*)(SVCXPRT *, xdrproc_t, void *))abort, 621 ops.xp_destroy = svc_vc_destroy; | 692} 693 694static void 695svc_vc_ops(xprt) 696 SVCXPRT *xprt; 697{ 698 static struct xp_ops ops; 699 static struct xp_ops2 ops2; --- 30 unchanged lines hidden (view full) --- 730 ops.xp_stat = rendezvous_stat; 731 ops.xp_getargs = 732 (bool_t (*)(SVCXPRT *, xdrproc_t, void *))abort; 733 ops.xp_reply = 734 (bool_t (*)(SVCXPRT *, struct rpc_msg *))abort; 735 ops.xp_freeargs = 736 (bool_t (*)(SVCXPRT *, xdrproc_t, void *))abort, 737 ops.xp_destroy = svc_vc_destroy; |
622 ops2.xp_control = svc_vc_control; | 738 ops2.xp_control = svc_vc_rendezvous_control; |
623 } 624 xprt->xp_ops = &ops; 625 xprt->xp_ops2 = &ops2; 626 mutex_unlock(&ops_lock); 627} 628 629int 630__msgread_withcred(sock, buf, cnt, cmp) --- 84 unchanged lines hidden (view full) --- 715 return (-1); 716 717 cmcred = __svc_getcallercreds(transp); 718 if (cmcred == NULL) 719 return (-1); 720 *uid = cmcred->cmcred_euid; 721 return (0); 722} | 739 } 740 xprt->xp_ops = &ops; 741 xprt->xp_ops2 = &ops2; 742 mutex_unlock(&ops_lock); 743} 744 745int 746__msgread_withcred(sock, buf, cnt, cmp) --- 84 unchanged lines hidden (view full) --- 831 return (-1); 832 833 cmcred = __svc_getcallercreds(transp); 834 if (cmcred == NULL) 835 return (-1); 836 *uid = cmcred->cmcred_euid; 837 return (0); 838} |
839 840/* 841 * Destroy xprts that have not have had any activity in 'timeout' seconds. 842 * If 'cleanblock' is true, blocking connections (the default) are also 843 * cleaned. If timeout is 0, the least active connection is picked. 844 */ 845bool_t 846__svc_clean_idle(fd_set *fds, int timeout, bool_t cleanblock) 847{ 848 int i, ncleaned; 849 SVCXPRT *xprt, *least_active; 850 struct timeval tv, tdiff, tmax; 851 struct cf_conn *cd; 852 853 gettimeofday(&tv, NULL); 854 tmax.tv_sec = tmax.tv_usec = 0; 855 least_active = NULL; 856 rwlock_wrlock(&svc_fd_lock); 857 for (i = ncleaned = 0; i <= svc_maxfd; i++) { 858 if (FD_ISSET(i, fds)) { 859 xprt = __svc_xports[i]; 860 if (xprt == NULL || xprt->xp_ops == NULL || 861 xprt->xp_ops->xp_recv != svc_vc_recv) 862 continue; 863 cd = (struct cf_conn *)xprt->xp_p1; 864 if (!cleanblock && !cd->nonblock) 865 continue; 866 if (timeout == 0) { 867 timersub(&tv, &cd->last_recv_time, &tdiff); 868 if (timercmp(&tdiff, &tmax, >)) { 869 tmax = tdiff; 870 least_active = xprt; 871 } 872 continue; 873 } 874 if (tv.tv_sec - cd->last_recv_time.tv_sec > timeout) { 875 __xprt_unregister_unlocked(xprt); 876 __svc_vc_dodestroy(xprt); 877 ncleaned++; 878 } 879 } 880 } 881 if (timeout == 0 && least_active != NULL) { 882 __xprt_unregister_unlocked(least_active); 883 __svc_vc_dodestroy(least_active); 884 ncleaned++; 885 } 886 rwlock_unlock(&svc_fd_lock); 887 return ncleaned > 0 ? TRUE : FALSE; 888} |
|