ReactOS  0.4.14-dev-337-gf981a68
svc_dg.c File Reference
#include <wintirpc.h>
#include <reentrant.h>
#include <sys/types.h>
#include <rpc/rpc.h>
#include <rpc/svc_dg.h>
#include <errno.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include "rpc_com.h"
Include dependency graph for svc_dg.c:

Go to the source code of this file.

Classes

struct  cache_node
 
struct  cl_cache
 

Macros

#define su_data(xprt)   ((struct svc_dg_data *)(xprt->xp_p2))
 
#define rpc_buffer(xprt)   ((xprt)->xp_p1)
 
#define MAX(a, b)   (((a) > (b)) ? (a) : (b))
 
#define SPARSENESS   4 /* 75% sparse */
 
#define ALLOC(type, size)   (type *) mem_alloc((sizeof (type) * (size)))
 
#define MEMZERO(addr, type, size)   (void) memset((void *) (addr), 0, sizeof (type) * (int) (size))
 
#define FREE(addr, type, size)   mem_free((addr), (sizeof (type) * (size)))
 
#define CACHE_LOC(transp, xid)
 

Typedefs

typedef struct cache_nodecache_ptr
 

Functions

static void svc_dg_ops (SVCXPRT *)
 
static enum xprt_stat svc_dg_stat (SVCXPRT *)
 
static bool_t svc_dg_recv (SVCXPRT *, struct rpc_msg *)
 
static bool_t svc_dg_reply (SVCXPRT *, struct rpc_msg *)
 
static bool_t svc_dg_getargs (SVCXPRT *, xdrproc_t, void *)
 
static bool_t svc_dg_freeargs (SVCXPRT *, xdrproc_t, void *)
 
static void svc_dg_destroy (SVCXPRT *)
 
static bool_t svc_dg_control (SVCXPRT *, const u_int, void *)
 
static int cache_get (SVCXPRT *, struct rpc_msg *, char **, size_t *)
 
static void cache_set (SVCXPRT *, size_t)
 
int svc_dg_enablecache (SVCXPRT *, u_int)
 
SVCXPRTsvc_dg_create (int fd, u_int sendsize, u_int recvsize)
 

Variables

static const char svc_dg_str [] = "svc_dg_create: %s"
 
static const char svc_dg_err1 [] = "could not get transport information"
 
static const char svc_dg_err2 [] = " transport does not support data transfer"
 
static const char __no_mem_str [] = "out of memory"
 
mutex_t dupreq_lock
 
static const char cache_enable_str [] = "svc_enablecache: %s %s"
 
static const char alloc_err [] = "could not allocate cache "
 
static const char enable_err [] = "cache already enabled"
 
static const char cache_set_str [] = "cache_set: %s"
 
static const char cache_set_err1 [] = "victim not found"
 
static const char cache_set_err2 [] = "victim alloc failed"
 
static const char cache_set_err3 [] = "could not allocate new rpc buffer"
 

Macro Definition Documentation

◆ ALLOC

#define ALLOC (   type,
  size 
)    (type *) mem_alloc((sizeof (type) * (size)))

Definition at line 321 of file svc_dg.c.

◆ CACHE_LOC

#define CACHE_LOC (   transp,
  xid 
)
Value:
(xid % (SPARSENESS * ((struct cl_cache *) \
su_data(transp)->su_cache)->uc_size))
LONGLONG xid
Definition: nfs41_driver.c:106
#define SPARSENESS
Definition: svc_dg.c:319
u_int uc_size
Definition: svc_dg.c:358
#define su_data(xprt)
Definition: svc_dg.c:61

Definition at line 371 of file svc_dg.c.

◆ FREE

#define FREE (   addr,
  type,
  size 
)    mem_free((addr), (sizeof (type) * (size)))

Definition at line 327 of file svc_dg.c.

◆ MAX

#define MAX (   a,
  b 
)    (((a) > (b)) ? (a) : (b))

Definition at line 65 of file svc_dg.c.

◆ MEMZERO

#define MEMZERO (   addr,
  type,
  size 
)    (void) memset((void *) (addr), 0, sizeof (type) * (int) (size))

Definition at line 324 of file svc_dg.c.

◆ rpc_buffer

#define rpc_buffer (   xprt)    ((xprt)->xp_p1)

Definition at line 62 of file svc_dg.c.

◆ SPARSENESS

#define SPARSENESS   4 /* 75% sparse */

Definition at line 319 of file svc_dg.c.

◆ su_data

#define su_data (   xprt)    ((struct svc_dg_data *)(xprt->xp_p2))

Definition at line 61 of file svc_dg.c.

Typedef Documentation

◆ cache_ptr

Definition at line 333 of file svc_dg.c.

Function Documentation

◆ cache_get()

static int cache_get ( SVCXPRT xprt,
struct rpc_msg msg,
char **  replyp,
size_t replylenp 
)
static

Definition at line 533 of file svc_dg.c.

538 {
539  u_int loc;
540  cache_ptr ent;
541  struct svc_dg_data *su = su_data(xprt);
542  struct cl_cache *uc = (struct cl_cache *) su->su_cache;
543 #ifdef RPC_CACHE_DEBUG
544  struct netconfig *nconf;
545  char *uaddr;
546 #endif
547 
549  loc = CACHE_LOC(xprt, su->su_xid);
550  for (ent = uc->uc_entries[loc]; ent != NULL; ent = ent->cache_next) {
551  if (ent->cache_xid == su->su_xid &&
552  ent->cache_proc == msg->rm_call.cb_proc &&
553  ent->cache_vers == msg->rm_call.cb_vers &&
554  ent->cache_prog == msg->rm_call.cb_prog &&
555  ent->cache_addr.len == xprt->xp_rtaddr.len &&
556  (memcmp(ent->cache_addr.buf, xprt->xp_rtaddr.buf,
557  xprt->xp_rtaddr.len) == 0)) {
558 #ifdef RPC_CACHE_DEBUG
559  if (nconf = getnetconfigent(xprt->xp_netid)) {
560  uaddr = taddr2uaddr(nconf, &xprt->xp_rtaddr);
561  freenetconfigent(nconf);
562  printf(
563  "cache entry found for xid=%x prog=%d vers=%d proc=%d for rmtaddr=%s\n",
564  su->su_xid, msg->rm_call.cb_prog,
565  msg->rm_call.cb_vers,
566  msg->rm_call.cb_proc, uaddr);
567  free(uaddr);
568  }
569 #endif
570  *replyp = ent->cache_reply;
571  *replylenp = ent->cache_replylen;
573  return (1);
574  }
575  }
576  /*
577  * Failed to find entry
578  * Remember a few things so we can do a set later
579  */
580  uc->uc_proc = msg->rm_call.cb_proc;
581  uc->uc_vers = msg->rm_call.cb_vers;
582  uc->uc_prog = msg->rm_call.cb_prog;
584  return (0);
585 }
mutex_t dupreq_lock
Definition: mt_misc.c:59
rpcprog_t cache_prog
Definition: svc_dg.c:341
#define CACHE_LOC(transp, xid)
Definition: svc_dg.c:371
int memcmp(void *Buffer1, void *Buffer2, ACPI_SIZE Count)
Definition: utclib.c:112
u_int32_t cache_xid
Definition: svc_dg.c:338
#define free
Definition: debug_ros.c:5
cache_ptr * uc_entries
Definition: svc_dg.c:359
#define mutex_lock(m)
Definition: reentrant.h:128
cache_ptr cache_next
Definition: svc_dg.c:351
#define mutex_unlock(m)
Definition: reentrant.h:129
void freenetconfigent(struct netconfig *netconfigp)
Definition: getnetconfig.c:530
smooth NULL
Definition: ftsmooth.c:416
struct netconfig * getnetconfigent(char *netid) const
Definition: getnetconfig.c:432
rpcproc_t uc_proc
Definition: svc_dg.c:364
char * cache_reply
Definition: svc_dg.c:346
void * su_cache
Definition: svc_dg.h:47
rpcproc_t cache_proc
Definition: svc_dg.c:339
u_int32_t su_xid
Definition: svc_dg.h:44
struct netbuf cache_addr
Definition: svc_dg.c:342
size_t cache_replylen
Definition: svc_dg.c:347
struct netbuf xp_rtaddr
Definition: svc.h:120
UINT32 u_int
Definition: types.h:82
rpcprog_t uc_prog
Definition: svc_dg.c:362
rpcvers_t uc_vers
Definition: svc_dg.c:363
rpcvers_t cache_vers
Definition: svc_dg.c:340
#define su_data(xprt)
Definition: svc_dg.c:61
#define msg(x)
Definition: auth_time.c:54
char * taddr2uaddr(const struct netconfig *nconf, const struct netbuf *nbuf)
Definition: rpc_generic.c:609
char * xp_netid
Definition: svc.h:118
#define printf
Definition: config.h:203

Referenced by svc_dg_recv().

◆ cache_set()

static void cache_set ( SVCXPRT xprt,
size_t  replylen 
)
static

Definition at line 443 of file svc_dg.c.

446 {
447  cache_ptr victim;
448  cache_ptr *vicp;
449  struct svc_dg_data *su = su_data(xprt);
450  struct cl_cache *uc = (struct cl_cache *) su->su_cache;
451  u_int loc;
452  char *newbuf;
453 #ifdef RPC_CACHE_DEBUG
454  struct netconfig *nconf;
455  char *uaddr;
456 #endif
457 
459  /*
460  * Find space for the new entry, either by
461  * reusing an old entry, or by mallocing a new one
462  */
463  victim = uc->uc_fifo[uc->uc_nextvictim];
464  if (victim != NULL) {
465  loc = CACHE_LOC(xprt, victim->cache_xid);
466  for (vicp = &uc->uc_entries[loc];
467  *vicp != NULL && *vicp != victim;
468  vicp = &(*vicp)->cache_next)
469  ;
470  if (*vicp == NULL) {
471  // XXX warnx(cache_set_str, cache_set_err1);
473  return;
474  }
475  *vicp = victim->cache_next; /* remove from cache */
476  newbuf = victim->cache_reply;
477  } else {
478  victim = ALLOC(struct cache_node, 1);
479  if (victim == NULL) {
480  // XXX warnx(cache_set_str, cache_set_err2);
482  return;
483  }
484  newbuf = mem_alloc(su->su_iosz);
485  if (newbuf == NULL) {
486  // XXX warnx(cache_set_str, cache_set_err3);
487  FREE(victim, struct cache_node, 1);
489  return;
490  }
491  }
492 
493  /*
494  * Store it away
495  */
496 #ifdef RPC_CACHE_DEBUG
497  if (nconf = getnetconfigent(xprt->xp_netid)) {
498  uaddr = taddr2uaddr(nconf, &xprt->xp_rtaddr);
499  freenetconfigent(nconf);
500  printf(
501  "cache set for xid= %x prog=%d vers=%d proc=%d for rmtaddr=%s\n",
502  su->su_xid, uc->uc_prog, uc->uc_vers,
503  uc->uc_proc, uaddr);
504  free(uaddr);
505  }
506 #endif
507  victim->cache_replylen = replylen;
508  victim->cache_reply = rpc_buffer(xprt);
509  rpc_buffer(xprt) = newbuf;
510  xdrmem_create(&(su->su_xdrs), rpc_buffer(xprt),
511  su->su_iosz, XDR_ENCODE);
512  victim->cache_xid = su->su_xid;
513  victim->cache_proc = uc->uc_proc;
514  victim->cache_vers = uc->uc_vers;
515  victim->cache_prog = uc->uc_prog;
516  victim->cache_addr = xprt->xp_rtaddr;
517  victim->cache_addr.buf = ALLOC(char, xprt->xp_rtaddr.len);
518  (void) memcpy(victim->cache_addr.buf, xprt->xp_rtaddr.buf,
519  (size_t)xprt->xp_rtaddr.len);
520  loc = CACHE_LOC(xprt, victim->cache_xid);
521  victim->cache_next = uc->uc_entries[loc];
522  uc->uc_entries[loc] = victim;
523  uc->uc_fifo[uc->uc_nextvictim++] = victim;
524  uc->uc_nextvictim %= uc->uc_size;
526 }
mutex_t dupreq_lock
Definition: mt_misc.c:59
rpcprog_t cache_prog
Definition: svc_dg.c:341
#define CACHE_LOC(transp, xid)
Definition: svc_dg.c:371
struct png_info_def **typedef void(__cdecl typeof(png_destroy_read_struct))(struct png_struct_def **
Definition: typeof.h:49
u_int32_t cache_xid
Definition: svc_dg.c:338
#define free
Definition: debug_ros.c:5
size_t su_iosz
Definition: svc_dg.h:43
cache_ptr * uc_entries
Definition: svc_dg.c:359
#define mutex_lock(m)
Definition: reentrant.h:128
cache_ptr cache_next
Definition: svc_dg.c:351
#define mutex_unlock(m)
Definition: reentrant.h:129
#define ALLOC(type, size)
Definition: svc_dg.c:321
#define mem_alloc(bsize)
Definition: types.h:123
cache_ptr * uc_fifo
Definition: svc_dg.c:360
void freenetconfigent(struct netconfig *netconfigp)
Definition: getnetconfig.c:530
smooth NULL
Definition: ftsmooth.c:416
struct netconfig * getnetconfigent(char *netid) const
Definition: getnetconfig.c:432
rpcproc_t uc_proc
Definition: svc_dg.c:364
char * cache_reply
Definition: svc_dg.c:346
#define FREE(addr, type, size)
Definition: svc_dg.c:327
void * su_cache
Definition: svc_dg.h:47
u_int uc_size
Definition: svc_dg.c:358
rpcproc_t cache_proc
Definition: svc_dg.c:339
Definition: xdr.h:85
#define memcpy(s1, s2, n)
Definition: mkisofs.h:878
u_int32_t su_xid
Definition: svc_dg.h:44
struct netbuf cache_addr
Definition: svc_dg.c:342
size_t cache_replylen
Definition: svc_dg.c:347
struct netbuf xp_rtaddr
Definition: svc.h:120
UINT32 u_int
Definition: types.h:82
XDR su_xdrs
Definition: svc_dg.h:45
rpcprog_t uc_prog
Definition: svc_dg.c:362
rpcvers_t uc_vers
Definition: svc_dg.c:363
void xdrmem_create(XDR *xdrs, char *addr, u_int size, enum xdr_op op)
Definition: xdr_mem.c:94
rpcvers_t cache_vers
Definition: svc_dg.c:340
#define su_data(xprt)
Definition: svc_dg.c:61
#define rpc_buffer(xprt)
Definition: svc_dg.c:62
u_int uc_nextvictim
Definition: svc_dg.c:361
char * taddr2uaddr(const struct netconfig *nconf, const struct netbuf *nbuf)
Definition: rpc_generic.c:609
char * xp_netid
Definition: svc.h:118
#define printf
Definition: config.h:203

Referenced by svc_dg_reply().

◆ svc_dg_control()

static bool_t svc_dg_control ( SVCXPRT xprt,
const u_int  rq,
void in 
)
static

Definition at line 275 of file svc_dg.c.

279 {
280  return (FALSE);
281 }

Referenced by svc_dg_ops().

◆ svc_dg_create()

SVCXPRT* svc_dg_create ( int  fd,
u_int  sendsize,
u_int  recvsize 
)

Definition at line 95 of file svc_dg.c.

99 {
100  SVCXPRT *xprt;
101  struct svc_dg_data *su = NULL;
102  struct __rpc_sockinfo si;
103  struct sockaddr_storage ss;
104  socklen_t slen;
105 
106  if (!__rpc_fd2sockinfo(fd, &si)) {
107  // XXX warnx(svc_dg_str, svc_dg_err1);
108  return (NULL);
109  }
110  /*
111  * Find the receive and the send size
112  */
113  sendsize = __rpc_get_t_size(si.si_af, si.si_proto, (int)sendsize);
114  recvsize = __rpc_get_t_size(si.si_af, si.si_proto, (int)recvsize);
115  if ((sendsize == 0) || (recvsize == 0)) {
116  // XXX warnx(svc_dg_str, svc_dg_err2);
117  return (NULL);
118  }
119 
120  xprt = mem_alloc(sizeof (SVCXPRT));
121  if (xprt == NULL)
122  goto freedata;
123  memset(xprt, 0, sizeof (SVCXPRT));
124 
125  su = mem_alloc(sizeof (*su));
126  if (su == NULL)
127  goto freedata;
128  su->su_iosz = ((MAX(sendsize, recvsize) + 3) / 4) * 4;
129  if ((rpc_buffer(xprt) = mem_alloc(su->su_iosz)) == NULL)
130  goto freedata;
131  xdrmem_create(&(su->su_xdrs), rpc_buffer(xprt), su->su_iosz,
132  XDR_DECODE);
133  su->su_cache = NULL;
134  xprt->xp_fd = fd;
135  xprt->xp_p2 = su;
136  xprt->xp_verf.oa_base = su->su_verfbody;
137  svc_dg_ops(xprt);
138  xprt->xp_rtaddr.maxlen = sizeof (struct sockaddr_storage);
139 
140  slen = sizeof ss;
141  if (getsockname(fd, (struct sockaddr *)(void *)&ss, &slen) == SOCKET_ERROR)
142  goto freedata;
143  __rpc_set_netbuf(&xprt->xp_ltaddr, &ss, slen);
144 
145  xprt_register(xprt);
146  return (xprt);
147 freedata:
148  // XXX (void) warnx(svc_dg_str, __no_mem_str);
149  if (xprt) {
150  if (su)
151  (void) mem_free(su, sizeof (*su));
152  (void) mem_free(xprt, sizeof (SVCXPRT));
153  }
154  return (NULL);
155 }
u_int __rpc_get_t_size(int af, int proto, int size)
Definition: rpc_generic.c:139
#define SOCKET_ERROR
Definition: winsock.h:333
struct png_info_def **typedef void(__cdecl typeof(png_destroy_read_struct))(struct png_struct_def **
Definition: typeof.h:49
size_t su_iosz
Definition: svc_dg.h:43
static int fd
Definition: io.c:51
#define mem_alloc(bsize)
Definition: types.h:123
int __rpc_fd2sockinfo(SOCKET fd, struct __rpc_sockinfo *sip)
Definition: rpc_generic.c:481
static void svc_dg_ops(SVCXPRT *)
Definition: svc_dg.c:284
#define MAX(a, b)
Definition: svc_dg.c:65
smooth NULL
Definition: ftsmooth.c:416
struct netbuf xp_ltaddr
Definition: svc.h:119
SOCKET xp_fd
Definition: svc.h:91
void xprt_register(SVCXPRT *xprt)
Definition: svc.c:97
void * su_cache
Definition: svc_dg.h:47
int socklen_t
Definition: tcp.c:35
struct netbuf * __rpc_set_netbuf(struct netbuf *, const void *, size_t)
Definition: rpc_generic.c:951
char su_verfbody[MAX_AUTH_BYTES]
Definition: svc_dg.h:46
void * xp_p2
Definition: svc.h:124
struct netbuf xp_rtaddr
Definition: svc.h:120
XDR su_xdrs
Definition: svc_dg.h:45
void xdrmem_create(XDR *xdrs, char *addr, u_int size, enum xdr_op op)
Definition: xdr_mem.c:94
#define rpc_buffer(xprt)
Definition: svc_dg.c:62
struct opaque_auth xp_verf
Definition: svc.h:121
Definition: xdr.h:86
#define mem_free(ptr, bsize)
Definition: types.h:124
#define ss
Definition: i386-dis.c:432
#define memset(x, y, z)
Definition: compat.h:39
INT WSAAPI getsockname(IN SOCKET s, OUT LPSOCKADDR name, IN OUT INT FAR *namelen)
Definition: sockctrl.c:213

Referenced by svc_tli_create().

◆ svc_dg_destroy()

static void svc_dg_destroy ( SVCXPRT xprt)
static

Definition at line 253 of file svc_dg.c.

255 {
256  struct svc_dg_data *su = su_data(xprt);
257 
258  xprt_unregister(xprt);
259  if (xprt->xp_fd != -1)
260  (void)closesocket(xprt->xp_fd);
261  XDR_DESTROY(&(su->su_xdrs));
262  (void) mem_free(rpc_buffer(xprt), su->su_iosz);
263  (void) mem_free(su, sizeof (*su));
264  if (xprt->xp_rtaddr.buf)
265  (void) mem_free(xprt->xp_rtaddr.buf, xprt->xp_rtaddr.maxlen);
266  if (xprt->xp_ltaddr.buf)
267  (void) mem_free(xprt->xp_ltaddr.buf, xprt->xp_ltaddr.maxlen);
268  if (xprt->xp_tp)
269  (void) free(xprt->xp_tp);
270  (void) mem_free(xprt, sizeof (SVCXPRT));
271 }
struct png_info_def **typedef void(__cdecl typeof(png_destroy_read_struct))(struct png_struct_def **
Definition: typeof.h:49
#define closesocket
#define free
Definition: debug_ros.c:5
size_t su_iosz
Definition: svc_dg.h:43
void xprt_unregister(SVCXPRT *xprt)
Definition: svc.c:128
char * xp_tp
Definition: svc.h:117
struct netbuf xp_ltaddr
Definition: svc.h:119
SOCKET xp_fd
Definition: svc.h:91
struct netbuf xp_rtaddr
Definition: svc.h:120
XDR su_xdrs
Definition: svc_dg.h:45
#define su_data(xprt)
Definition: svc_dg.c:61
#define rpc_buffer(xprt)
Definition: svc_dg.c:62
#define mem_free(ptr, bsize)
Definition: types.h:124
#define XDR_DESTROY(xdrs)
Definition: xdr.h:214

Referenced by svc_dg_ops().

◆ svc_dg_enablecache()

int svc_dg_enablecache ( SVCXPRT transp,
u_int  size 
)

Definition at line 386 of file svc_dg.c.

389 {
390  struct svc_dg_data *su = su_data(transp);
391  struct cl_cache *uc;
392 
394  if (su->su_cache != NULL) {
395  // XXX (void) warnx(cache_enable_str, enable_err, " ");
397  return (0);
398  }
399  uc = ALLOC(struct cl_cache, 1);
400  if (uc == NULL) {
401  // XXX warnx(cache_enable_str, alloc_err, " ");
403  return (0);
404  }
405  uc->uc_size = size;
406  uc->uc_nextvictim = 0;
408  if (uc->uc_entries == NULL) {
409  // XXX warnx(cache_enable_str, alloc_err, "data");
410  FREE(uc, struct cl_cache, 1);
412  return (0);
413  }
415  uc->uc_fifo = ALLOC(cache_ptr, size);
416  if (uc->uc_fifo == NULL) {
417  // XXX warnx(cache_enable_str, alloc_err, "fifo");
419  FREE(uc, struct cl_cache, 1);
421  return (0);
422  }
423  MEMZERO(uc->uc_fifo, cache_ptr, size);
424  su->su_cache = (char *)(void *)uc;
426  return (1);
427 }
mutex_t dupreq_lock
Definition: mt_misc.c:59
#define MEMZERO(addr, type, size)
Definition: svc_dg.c:324
cache_ptr * uc_entries
Definition: svc_dg.c:359
#define SPARSENESS
Definition: svc_dg.c:319
#define mutex_lock(m)
Definition: reentrant.h:128
#define mutex_unlock(m)
Definition: reentrant.h:129
#define ALLOC(type, size)
Definition: svc_dg.c:321
cache_ptr * uc_fifo
Definition: svc_dg.c:360
smooth NULL
Definition: ftsmooth.c:416
#define FREE(addr, type, size)
Definition: svc_dg.c:327
GLsizeiptr size
Definition: glext.h:5919
void * su_cache
Definition: svc_dg.h:47
u_int uc_size
Definition: svc_dg.c:358
#define su_data(xprt)
Definition: svc_dg.c:61
u_int uc_nextvictim
Definition: svc_dg.c:361

◆ svc_dg_freeargs()

static bool_t svc_dg_freeargs ( SVCXPRT xprt,
xdrproc_t  xdr_args,
void args_ptr 
)
static

Definition at line 241 of file svc_dg.c.

245 {
246  XDR *xdrs = &(su_data(xprt)->su_xdrs);
247 
248  xdrs->x_op = XDR_FREE;
249  return (*xdr_args)(xdrs, args_ptr);
250 }
Definition: xdr.h:103
enum xdr_op x_op
Definition: xdr.h:104
#define su_data(xprt)
Definition: svc_dg.c:61
Definition: xdr.h:87

Referenced by svc_dg_ops().

◆ svc_dg_getargs()

static bool_t svc_dg_getargs ( SVCXPRT xprt,
xdrproc_t  xdr_args,
void args_ptr 
)
static

Definition at line 232 of file svc_dg.c.

236 {
237  return (*xdr_args)(&(su_data(xprt)->su_xdrs), args_ptr);
238 }
#define su_data(xprt)
Definition: svc_dg.c:61

Referenced by svc_dg_ops().

◆ svc_dg_ops()

static void svc_dg_ops ( SVCXPRT xprt)
static

Definition at line 284 of file svc_dg.c.

286 {
287  static struct xp_ops ops;
288  static struct xp_ops2 ops2;
289  extern mutex_t ops_lock;
290 
291 /* VARIABLES PROTECTED BY ops_lock: ops */
292 
294  if (ops.xp_recv == NULL) {
295  ops.xp_recv = svc_dg_recv;
296  ops.xp_stat = svc_dg_stat;
297  ops.xp_getargs = svc_dg_getargs;
298  ops.xp_reply = svc_dg_reply;
299  ops.xp_freeargs = svc_dg_freeargs;
300  ops.xp_destroy = svc_dg_destroy;
301  ops2.xp_control = svc_dg_control;
302  }
303  xprt->xp_ops = &ops;
304  xprt->xp_ops2 = &ops2;
306 }
mutex_t ops_lock
Definition: mt_misc.c:71
static bool_t svc_dg_freeargs(SVCXPRT *, xdrproc_t, void *)
Definition: svc_dg.c:241
static void svc_dg_destroy(SVCXPRT *)
Definition: svc_dg.c:253
static bool_t svc_dg_recv(SVCXPRT *, struct rpc_msg *)
Definition: svc_dg.c:166
static bool_t svc_dg_getargs(SVCXPRT *, xdrproc_t, void *)
Definition: svc_dg.c:232
#define mutex_lock(m)
Definition: reentrant.h:128
#define mutex_unlock(m)
Definition: reentrant.h:129
smooth NULL
Definition: ftsmooth.c:416
static bool_t svc_dg_control(SVCXPRT *, const u_int, void *)
Definition: svc_dg.c:275
const struct __rpc_svcxprt::xp_ops * xp_ops
static enum xprt_stat svc_dg_stat(SVCXPRT *)
Definition: svc_dg.c:159
Definition: module.h:446
static bool_t svc_dg_reply(SVCXPRT *, struct rpc_msg *)
Definition: svc_dg.c:206
const struct __rpc_svcxprt::xp_ops2 * xp_ops2

Referenced by svc_dg_create().

◆ svc_dg_recv()

static bool_t svc_dg_recv ( SVCXPRT xprt,
struct rpc_msg msg 
)
static

Definition at line 166 of file svc_dg.c.

169 {
170  struct svc_dg_data *su = su_data(xprt);
171  XDR *xdrs = &(su->su_xdrs);
172  char *reply;
173  struct sockaddr_storage ss;
174  socklen_t alen;
175  size_t replylen;
176  ssize_t rlen;
177 
178 again:
179  alen = sizeof (struct sockaddr_storage);
180  rlen = recvfrom(xprt->xp_fd, rpc_buffer(xprt), su->su_iosz, 0,
181  (struct sockaddr *)(void *)&ss, &alen);
182  if (rlen == -1 && errno == EINTR)
183  goto again;
184  if (rlen == -1 || (rlen < (ssize_t)(4 * sizeof (u_int32_t))))
185  return (FALSE);
186  __rpc_set_netbuf(&xprt->xp_rtaddr, &ss, alen);
187 
188  __xprt_set_raddr(xprt, &ss);
189  xdrs->x_op = XDR_DECODE;
190  XDR_SETPOS(xdrs, 0);
191  if (! xdr_callmsg(xdrs, msg)) {
192  return (FALSE);
193  }
194  su->su_xid = msg->rm_xid;
195  if (su->su_cache != NULL) {
196  if (cache_get(xprt, msg, &reply, &replylen)) {
197  (void)sendto(xprt->xp_fd, reply, replylen, 0,
198  (struct sockaddr *)(void *)&ss, alen);
199  return (FALSE);
200  }
201  }
202  return (TRUE);
203 }
INT WSAAPI recvfrom(IN SOCKET s, OUT CHAR FAR *buf, IN INT len, IN INT flags, OUT LPSOCKADDR from, IN OUT INT FAR *fromlen)
Definition: recv.c:87
#define TRUE
Definition: types.h:120
static int cache_get(SVCXPRT *, struct rpc_msg *, char **, size_t *)
Definition: svc_dg.c:533
struct png_info_def **typedef void(__cdecl typeof(png_destroy_read_struct))(struct png_struct_def **
Definition: typeof.h:49
#define EINTR
Definition: acclib.h:80
size_t su_iosz
Definition: svc_dg.h:43
int errno
Definition: xdr.h:103
smooth NULL
Definition: ftsmooth.c:416
bool_t xdr_callmsg(XDR *xdrs, struct rpc_msg *cmsg)
Definition: rpc_callmsg.c:50
SOCKET xp_fd
Definition: svc.h:91
void * su_cache
Definition: svc_dg.h:47
enum xdr_op x_op
Definition: xdr.h:104
int socklen_t
Definition: tcp.c:35
struct netbuf * __rpc_set_netbuf(struct netbuf *, const void *, size_t)
Definition: rpc_generic.c:951
void __xprt_set_raddr(SVCXPRT *, const struct sockaddr_storage *)
Definition: svc_vc.c:111
u_int32_t su_xid
Definition: svc_dg.h:44
unsigned int u_int32_t
Definition: rosdhcp.h:35
int ssize_t
Definition: rosdhcp.h:48
#define XDR_SETPOS(xdrs, pos)
Definition: xdr.h:204
struct netbuf xp_rtaddr
Definition: svc.h:120
XDR su_xdrs
Definition: svc_dg.h:45
#define su_data(xprt)
Definition: svc_dg.c:61
#define rpc_buffer(xprt)
Definition: svc_dg.c:62
INT WSAAPI sendto(IN SOCKET s, IN CONST CHAR FAR *buf, IN INT len, IN INT flags, IN CONST struct sockaddr *to, IN INT tolen)
Definition: send.c:82
#define msg(x)
Definition: auth_time.c:54
Definition: xdr.h:86
#define ss
Definition: i386-dis.c:432

Referenced by svc_dg_ops().

◆ svc_dg_reply()

static bool_t svc_dg_reply ( SVCXPRT xprt,
struct rpc_msg msg 
)
static

Definition at line 206 of file svc_dg.c.

209 {
210  struct svc_dg_data *su = su_data(xprt);
211  XDR *xdrs = &(su->su_xdrs);
212  bool_t stat = FALSE;
213  size_t slen;
214 
215  xdrs->x_op = XDR_ENCODE;
216  XDR_SETPOS(xdrs, 0);
217  msg->rm_xid = su->su_xid;
218  if (xdr_replymsg(xdrs, msg)) {
219  slen = XDR_GETPOS(xdrs);
220  if (sendto(xprt->xp_fd, rpc_buffer(xprt), slen, 0,
221  (struct sockaddr *)xprt->xp_rtaddr.buf,
222  (socklen_t)xprt->xp_rtaddr.len) == (ssize_t) slen) {
223  stat = TRUE;
224  if (su->su_cache)
225  cache_set(xprt, slen);
226  }
227  }
228  return (stat);
229 }
#define TRUE
Definition: types.h:120
static void cache_set(SVCXPRT *, size_t)
Definition: svc_dg.c:443
#define XDR_GETPOS(xdrs)
Definition: xdr.h:199
int32_t bool_t
Definition: types.h:101
Definition: xdr.h:103
SOCKET xp_fd
Definition: svc.h:91
void * su_cache
Definition: svc_dg.h:47
enum xdr_op x_op
Definition: xdr.h:104
int socklen_t
Definition: tcp.c:35
Definition: xdr.h:85
Definition: stat.h:55
u_int32_t su_xid
Definition: svc_dg.h:44
int ssize_t
Definition: rosdhcp.h:48
#define XDR_SETPOS(xdrs, pos)
Definition: xdr.h:204
struct netbuf xp_rtaddr
Definition: svc.h:120
XDR su_xdrs
Definition: svc_dg.h:45
#define su_data(xprt)
Definition: svc_dg.c:61
#define rpc_buffer(xprt)
Definition: svc_dg.c:62
INT WSAAPI sendto(IN SOCKET s, IN CONST CHAR FAR *buf, IN INT len, IN INT flags, IN CONST struct sockaddr *to, IN INT tolen)
Definition: send.c:82
#define msg(x)
Definition: auth_time.c:54
bool_t xdr_replymsg(XDR *xdrs, struct rpc_msg *rmsg)
Definition: rpc_prot.c:188

Referenced by svc_dg_ops().

◆ svc_dg_stat()

static enum xprt_stat svc_dg_stat ( SVCXPRT xprt)
static

Definition at line 159 of file svc_dg.c.

161 {
162  return (XPRT_IDLE);
163 }
Definition: svc.h:84

Referenced by svc_dg_ops().

Variable Documentation

◆ __no_mem_str

const char __no_mem_str[] = "out of memory"
static

Definition at line 92 of file svc_dg.c.

◆ alloc_err

const char alloc_err[] = "could not allocate cache "
static

Definition at line 382 of file svc_dg.c.

◆ cache_enable_str

const char cache_enable_str[] = "svc_enablecache: %s %s"
static

Definition at line 381 of file svc_dg.c.

◆ cache_set_err1

const char cache_set_err1[] = "victim not found"
static

Definition at line 438 of file svc_dg.c.

◆ cache_set_err2

const char cache_set_err2[] = "victim alloc failed"
static

Definition at line 439 of file svc_dg.c.

◆ cache_set_err3

const char cache_set_err3[] = "could not allocate new rpc buffer"
static

Definition at line 440 of file svc_dg.c.

◆ cache_set_str

const char cache_set_str[] = "cache_set: %s"
static

Definition at line 437 of file svc_dg.c.

◆ dupreq_lock

mutex_t dupreq_lock

Definition at line 59 of file mt_misc.c.

Referenced by cache_get(), cache_set(), and svc_dg_enablecache().

◆ enable_err

const char enable_err[] = "cache already enabled"
static

Definition at line 383 of file svc_dg.c.

◆ svc_dg_err1

const char svc_dg_err1[] = "could not get transport information"
static

Definition at line 90 of file svc_dg.c.

◆ svc_dg_err2

const char svc_dg_err2[] = " transport does not support data transfer"
static

Definition at line 91 of file svc_dg.c.

◆ svc_dg_str

const char svc_dg_str[] = "svc_dg_create: %s"
static

Definition at line 89 of file svc_dg.c.