📄 tsapunitdata.c
字号:
tb -> tb_holding_tpdu = 0; return (tud -> tud_cc); } /* * Read the datagram socket for data. It returns number of bytes read. */ tud -> tud_qbuf.qb_forw = tud -> tud_qbuf.qb_back = &tud -> tud_qbuf; cc = (*tb -> tb_UnitDataRead) (sd, &tud -> tud_qbuf, secs, &socket, td); if (cc < 1) return 0;#ifdef HULADEBUG printf ("\n from tb_UnitDataRead %d bytes \n", cc); for (j=0; j<25; j++) printf (" %x ", *((tud -> tud_qbuf.qb_data) + j) );#endif/* * Format the tsap unit data structure. */ tud -> tud_sd = sd; bzero ( &tud -> tud_calling, sizeof tud -> tud_calling); bzero ( &tud -> tud_called, sizeof tud -> tud_called); na = tud -> tud_calling.ta_addrs; na -> na_type = NA_TCP; hp = gethostbyaddr ((char *) &socket.sin_addr, sizeof socket.sin_addr, socket.sin_family); (void) strcpy ( na-> na_domain, hp ? hp -> h_name : inet_ntoa (socket.sin_addr)); na -> na_port = socket.sin_port; na -> na_tset = NA_TSET_UDP; tud -> tud_calling.ta_naddr = 1; tud -> tud_calling.ta_selectlen = 0; tud -> tud_cc = cc; tud -> tud_base = tud -> tud_qbuf.qb_data; /* * Strip off the ISO T-UNITDATA header. For prototype purposes * this is done as a simple subroutine call. Ideally this should * be implemented as a bona-fide transport service. */ hlen = T_UnitDataRead (tb, tud, td); return (cc - hlen);}#if FALSE/* */ /* **************************************************************** * * * Set Asynchronous Unit Data Event Indications * * * * This routine sets the mask for handling unit data * * indications asynchromously. * * * **************************************************************** */int TSetUnitDataIndications (sd, data)int sd;IFP data;{ SBV smask; int result; register struct tsapblk *tb;/* * Check for missing parm. */ missingP (data);/* * Block any incomming signals while we do the read. */ smask = sigioblock ();/* * Find the current transport block and set the signal mask. */ tsapPsig (tb, sd);/* * Set the N+1 service routine to call with inbound data * and set the flags for asynchronous service. */ if (tb -> tb_UnitDataIndication == data) tb -> tb_flags |= TB_ASYN; else tb -> tb_flags &= ~TB_ASYN;/* * Now setup the signal event handler for inbound data. */ result = TUnitDataWakeUp (tb); (void) sigiomask (smask); return result;}/* *//* **************************************************************** * map transport descriptors for select() **************************************************************** */int TSelectUnitDataMask (sd, mask, nfds)int sd;fd_set *mask;int *nfds;{ SBV smask; register struct tsapblk *tb;/* * Check for missing parameters. */ missingP (mask); missingP (nfds);/* * Block any incomming signals while we set the mask. */ smask = sigioblock ();/* * Find the transport block for this socket descriptor. */ if ((tb = findtublk (sd)) == NULL) { (void) sigiomask (smask); return tusaplose ( td, DR_PARAMETER, NULLCP, TuErrString(UDERR_INVALID_XPORT) ); }/* * Now set the select mask. */ selmask (tb -> tb_fd, *mask, *nfds); (void) sigiomask (smask); return OK;}/* */ /* **************************************************************** * * * N-UNITDATA.indication * * * * This routines gets the NSAP unit data indications. This * * really gets the indications from the Transport Datagram * * service. This is for asynchronous interface only. * * * **************************************************************** */static int UNITDATAser (sig, code, sc)int sig;long code;struct sigcontext *sc;{ int n, nfds, sd; fd_set ifds, mask;#ifndef BSDSIGS SBV smask;#endif IFP disc; register struct tsapblk *tb, *tb2; struct TSAPdata txs; register struct TSAPdata *tx = &txs;#ifndef BSDSIGS (void) signal (SIGEMT, UNITDATAser); smask = sigioblock ();#endif for (;;) { n = 0; FD_ZERO (&ifds); for (tb = THead -> tb_forw; tb != THead; tb = tb -> tb_forw) if (tb -> tb_fd != NOTOK && (tb -> tb_flags & TB_ASYN)) { nfds = 0; FD_ZERO (&mask); selmask (tb -> tb_fd, mask, nfds); if ((*tb -> tb_UnitDataSelect) (nfds, &mask, NULLFD, NULLFD, 0) > OK) { FD_SET (tb -> tb_fd, &ifds); n++; } } if (n == 0) break; for (tb = THead -> tb_forw; tb != THead; tb = tb2) { tb2 = tb -> tb_forw; if (FD_ISSET (sd = tb -> tb_fd, &ifds)) { switch ((*tb -> tb_UnitDataRead) (tb, tx)) { case NOTOK: return tusaplose (td, DR_OPERATION, NULLCP, "Unit Read failed"); break; case OK: /* * Call the N+1 data handler. */ (*tb -> tb_UnitDataIndication) (sd, tx); break; case DONE: /* partially assembled TSDU */ break; } } } }/* * Post a signal back to the ISORE helper to handshake and * indicate completion of the data handler. */#ifndef SIGPOLL (void) kill (TPid, SIGEMT);#endif#ifndef BSDSIGS (void) sigiomask (smask);#endif}/* */#ifndef SIGPOLLstatic int TUnitDataWakeUp (tb)register struct tsapblk *tb;{ int i, nfds; fd_set mask; char buf1[10], buf2[10], buf3[10]; register struct isoservent *is; static int inited = 0; if (TPid > OK) { (void) kill (TPid, SIGTERM); TPid = NOTOK; } nfds = 0; FD_ZERO (&mask); for (tb = THead -> tb_forw; tb != THead; tb = tb -> tb_forw) if (tb -> tb_fd != NOTOK && (tb -> tb_flags & TB_ASYN)) selmask (tb -> tb_fd, mask, nfds); if (nfds == 0) return OK; if (nfds > sizeof (int) * 8) return tsaplose (td, DR_CONGEST, NULLCP, "you lose"); if (!inited) {#ifndef BSDSIGS int smask = sigsetmask (sigblock (0) & ~sigmask (SIGEMT));#endif (void) signal (SIGEMT, UNITDATAser);#ifndef BSDSIGS (void) sigiomask (smask);#endif inited++; } if ((is = getisoserventbyname ("udisore", "tsap")) == NULL) return tusaplose (td, DR_CONGEST, NULLCP, "ISO service tsap/isore not found"); (void) sprintf (buf1, "%d", nfds); *is -> is_tail++ = buf1; (void) sprintf (buf2, "0x%x", mask.fds_bits[0]); *is -> is_tail++ = buf2; (void) sprintf (buf3, "%d", getpid ()); *is -> is_tail++ = buf3; *is -> is_tail = NULL; for (i = 0; i < 5; i++) switch (TPid = vfork ()) { case NOTOK: continue; case OK: (void) signal (SIGEMT, SIG_DFL); (void) execv (*is -> is_vec, is -> is_vec); _exit (1); default: return OK; } return tusaplose (td, DR_CONGEST, NULLCP, "unable to fork");}#else#ifdef BSDSIGS#include <fcntl.h>#include <sys/ioctl.h>#else#include <sys/stropts.h>#endifstatic int TUnitDataWakeUp (tb)register struct tsapblk *tb;{ int result; static int inited = 0; if (tb -> tb_flags & TB_ASYN) { if (!inited) { (void) signal (SIGPOLL, UNITDATAser); inited++; }#ifdef BSDSIGS if (fcntl (tb -> tb_fd, F_SETOWN, getpid ()) == NOTOK) return tusaplose (td, DR_CONGEST, "fcntl F_SETOWN"); if ((result = fcntl (tb -> tb_fd, F_GETFL, 0x00)) == NOTOK) return tusaplose (td, DR_CONGEST, "fcntl F_GETFL"); result |= FASYNC; if (fcntl (tb -> tb_fd, F_SETFL, result) == NOTOK) return tusaplose (td, DR_CONGEST, "fcntl F_SETFL");#else/* if (ioctl (tb -> tb_fd, I_GETSIG, &result) == NOTOK) result = 0; result |= S_INPUT; if (ioctl (tb -> tb_fd, I_SETSIG, result) == NOTOK) return tsaplose (td, DR_CONGEST, "failed", "ioctl I_SETSIG 0x%x", result); */ return tusaplose (td, DR_CONGEST, "asynchronous operations not yet supported under SVR3");#endif } else {#ifdef BSDSIGS if ((result = fcntl (tb -> tb_fd, F_GETFL, 0x00)) == NOTOK) return tusaplose (td, DR_CONGEST, "fcntl F_GETFL"); result &= ~FASYNC; if (fcntl (tb -> tb_fd, F_SETFL, result) == NOTOK) return tusaplose (td, DR_CONGEST, "fcntl F_SETFL 0x%x");#else if (ioctl (tb -> tb_fd, I_GETSIG, &result) == NOTOK) return tusaplose (td, DR_CONGEST, "ioctl I_GETSIG"); result &= ~S_INPUT; if (ioctl (tb -> tb_fd, I_SETSIG, result) == NOTOK) return tusaplose (td, DR_CONGEST, "ioctl I_SETSIG ");#endif } return OK;}#endif/* */int newtuaddr (ta, na, tdest)register struct TSAPaddr *ta;register struct NSAPaddr *na;register struct TSAPaddr *tdest;{ register struct NSAPaddr *ndest = tdest -> ta_addrs; bzero ((char *) tdest, sizeof(struct TSAPaddr)); if (tdest -> ta_selectlen = ta -> ta_selectlen) bcopy (ta -> ta_selector, tdest -> ta_selector, ta -> ta_selectlen); if (na) { ndest->na_type = na->na_type; switch (na->na_type) { case NA_NSAP: bcopy (na->na_address, ndest->na_address, NASIZE); ndest->na_addrlen = na->na_addrlen; break; case NA_TCP: bcopy (na->na_domain, ndest->na_domain, NASIZE); ndest->na_port = na->na_port; ndest->na_tset = na->na_tset; break; default: break; } tdest -> ta_naddr = 1; } return OK;}#endif /* if FALSE *//* */static struct TSAPaddr *newtuaddr (ta, na)register struct TSAPaddr *ta;register struct NSAPaddr *na;{ static struct TSAPaddr tzs; register struct TSAPaddr *tz = &tzs; register struct NSAPaddr *nz = tz -> ta_addrs; bzero ((char *) tz, sizeof *tz); if (tz -> ta_selectlen = ta -> ta_selectlen) bcopy (ta -> ta_selector, tz -> ta_selector, ta -> ta_selectlen); if (na) { *nz = *na; tz -> ta_naddr = 1; } return tz;}#endif /* if HULA */
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -