DOC HOME SITE MAP MAN PAGES GNU INFO SEARCH PRINT BOOK
 
Programming with the X/Open Transport Interface (XTI)

An example connectionless-mode transaction server

The following code represents the connectionless-mode transaction server program described in ``Connectionless-mode service''. This server waits for incoming datagram queries, and then processes each query and sends a response.

   #include <stdio.h>
   #include <fcntl.h>
   #include <xti.h>
   

#define SRV_ADDR 2 /* server's well known address */

main() { int fd; int flags; struct t_bind *bind; struct t_unitdata *ud; struct t_uderr *uderr;

if ((fd = t_open("/dev/tidg", O_RDWR, NULL)) < 0) { t_error("unable to open /dev/provider"); exit(1); }

if ((bind = (struct t_bind *)t_alloc(fd, T_BIND, T_ADDR)) == NULL) { t_error("t_alloc of t_bind structure failed"); exit(2); } bind->addr.len = sizeof(int); *(int *)bind->addr.buf = SRV_ADDR; bind->qlen = 0;

if (t_bind(fd, bind, NULL) < 0) { t_error("t_bind failed"); exit(3); }

if ((ud = (struct t_unitdata *)t_alloc(fd, T_UNITDATA, T_ALL)) == NULL) { t_error("t_alloc of t_unitdata structure failed"); exit(5); } if ((uderr = (struct t_uderr *)t_alloc(fd, T_UDERROR, T_ALL)) == NULL) { t_error("t_alloc of t_uderr structure failed"); exit(6); }

while (1) { if (t_rcvudata(fd, ud, &flags) < 0) { if (t_errno == TLOOK) { /* * Error on previously sent datagram */ if (t_rcvuderr(fd, uderr) < 0) { t_error("t_rcvuderr failed"); exit(7); } fprintf(stderr, "bad datagram, error = %d\n", uderr->error); continue; } t_error("t_rcvudata failed"); exit(8); }

/* * query() processes the request and places the * response in ud->udata.buf, setting ud->udata.len */ query(ud);

if (t_sndudata(fd, ud, 0) < 0) { t_error("t_sndudata failed"); exit(9); } } }

query(ud) struct t_unitdata *ud; { /* Merely a stub for simplicity */ }


© 2004 The SCO Group, Inc. All rights reserved.
UnixWare 7 Release 7.1.4 - 27 April 2004