📄 stream.c
字号:
/* * Copyright (c) 1993, 1994, 1995, 1996 Rick Sladkey <jrs@world.std.com> * Copyright (c) 1996-1999 Wichert Akkerman <wichert@cistron.nl> * All rights reserved. * * Redistribution and use in source and binary forms, with or without * modification, are permitted provided that the following conditions * are met: * 1. Redistributions of source code must retain the above copyright * notice, this list of conditions and the following disclaimer. * 2. Redistributions in binary form must reproduce the above copyright * notice, this list of conditions and the following disclaimer in the * documentation and/or other materials provided with the distribution. * 3. The name of the author may not be used to endorse or promote products * derived from this software without specific prior written permission. * * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. * * $Id: stream.c,v 1.9 2000/10/13 12:47:12 wichert Exp $ */#include "defs.h"#if defined(HAVE_SYS_STREAM_H) || defined(linux) || defined(FREEBSD)#if defined(linux)#ifdef HAVE_SYS_POLL_H#include <sys/poll.h>#endif#define RS_HIPRI 1struct strbuf { int maxlen; /* no. of bytes in buffer */ int len; /* no. of bytes returned */ char *buf; /* pointer to data */};#define MORECTL 1#define MOREDATA 2#else /* linux */#ifndef FREEBSD#include <stropts.h>#include <poll.h>#include <sys/conf.h>#include <sys/stream.h>#include <sys/tihdr.h>#else /* FREEBSD */#include <poll.h>#endif /* FREEBSD */#endif /* linux */#ifdef HAVE_SYS_TIUSER_H#include <sys/tiuser.h>#include <sys/sockmod.h>#include <sys/timod.h>#endif /* HAVE_SYS_TIUSER_H */#ifndef FREEBSDstatic struct xlat msgflags[] = { { RS_HIPRI, "RS_HIPRI" }, { 0, NULL },};static voidprintstrbuf(tcp, sbp, getting)struct tcb *tcp;struct strbuf *sbp;int getting;{ if (sbp->maxlen == -1 && getting) tprintf("{maxlen=-1}"); else { tprintf("{"); if (getting) tprintf("maxlen=%d, ", sbp->maxlen); tprintf("len=%d, buf=", sbp->len); printstr(tcp, (unsigned long) sbp->buf, sbp->len); tprintf("}"); }}static voidprintstrbufarg(tcp, arg, getting)struct tcb *tcp;int arg;int getting;{ struct strbuf buf; if (arg == 0) tprintf("NULL"); else if (umove(tcp, arg, &buf) < 0) tprintf("{...}"); else printstrbuf(tcp, &buf, getting); tprintf(", ");}intsys_putmsg(tcp)struct tcb *tcp;{ int i; if (entering(tcp)) { /* fd */ tprintf("%ld, ", tcp->u_arg[0]); /* control and data */ for (i = 1; i < 3; i++) printstrbufarg(tcp, tcp->u_arg[i], 0); /* flags */ if (!printflags(msgflags, tcp->u_arg[3])) tprintf("0"); } return 0;}intsys_getmsg(tcp)struct tcb *tcp;{ int i, flags; if (entering(tcp)) { /* fd */ tprintf("%lu, ", tcp->u_arg[0]); } else { if (syserror(tcp)) { tprintf("%#lx, %#lx, %#lx", tcp->u_arg[1], tcp->u_arg[2], tcp->u_arg[3]); return 0; } /* control and data */ for (i = 1; i < 3; i++) printstrbufarg(tcp, tcp->u_arg[i], 1); /* pointer to flags */ if (tcp->u_arg[3] == 0) tprintf("NULL"); else if (umove(tcp, tcp->u_arg[3], &flags) < 0) tprintf("[?]"); else { tprintf("["); if (!printflags(msgflags, flags)) tprintf("0"); tprintf("]"); } /* decode return value */ switch (tcp->u_rval) { case MORECTL: tcp->auxstr = "MORECTL"; break; case MORECTL|MOREDATA: tcp->auxstr = "MORECTL|MOREDATA"; break; case MOREDATA: tcp->auxstr = "MORECTL"; break; default: tcp->auxstr = NULL; break; } } return RVAL_HEX | RVAL_STR;}#ifdef HAVE_PUTPMSGstatic struct xlat pmsgflags[] = {#ifdef MSG_HIPRI { MSG_HIPRI, "MSG_HIPRI" },#endif#ifdef MSG_AND { MSG_ANY, "MSG_ANY" },#endif#ifdef MSG_BAND { MSG_BAND, "MSG_BAND" },#endif { 0, NULL },};intsys_putpmsg(tcp)struct tcb *tcp;{ int i; if (entering(tcp)) { /* fd */ tprintf("%ld, ", tcp->u_arg[0]); /* control and data */ for (i = 1; i < 3; i++) printstrbufarg(tcp, tcp->u_arg[i], 0); /* band */ tprintf("%ld, ", tcp->u_arg[3]); /* flags */ if (!printflags(pmsgflags, tcp->u_arg[4])) tprintf("0"); } return 0;}intsys_getpmsg(tcp)struct tcb *tcp;{ int i, flags; if (entering(tcp)) { /* fd */ tprintf("%lu, ", tcp->u_arg[0]); } else { if (syserror(tcp)) { tprintf("%#lx, %#lx, %#lx, %#lx", tcp->u_arg[1], tcp->u_arg[2], tcp->u_arg[3], tcp->u_arg[4]); return 0; } /* control and data */ for (i = 1; i < 3; i++) printstrbufarg(tcp, tcp->u_arg[i], 1); /* pointer to band */ printnum(tcp, tcp->u_arg[3], "%d"); tprintf(", "); /* pointer to flags */ if (tcp->u_arg[4] == 0) tprintf("NULL"); else if (umove(tcp, tcp->u_arg[4], &flags) < 0) tprintf("[?]"); else { tprintf("["); if (!printflags(pmsgflags, flags)) tprintf("0"); tprintf("]"); } /* decode return value */ switch (tcp->u_rval) { case MORECTL: tcp->auxstr = "MORECTL"; break; case MORECTL|MOREDATA: tcp->auxstr = "MORECTL|MOREDATA"; break; case MOREDATA: tcp->auxstr = "MORECTL"; break; default: tcp->auxstr = NULL; break; } } return RVAL_HEX | RVAL_STR;}#endif /* HAVE_PUTPMSG */#endif /* !FREEBSD */#ifdef HAVE_SYS_POLL_Hstatic struct xlat pollflags[] = {#ifdef POLLIN { POLLIN, "POLLIN" }, { POLLPRI, "POLLPRI" }, { POLLOUT, "POLLOUT" },#ifdef POLLRDNORM { POLLRDNORM, "POLLRDNORM" },#endif#ifdef POLLWRNORM { POLLWRNORM, "POLLWRNORM" },#endif#ifdef POLLRDBAND { POLLRDBAND, "POLLRDBAND" },#endif#ifdef POLLWRBAND { POLLWRBAND, "POLLWRBAND" },#endif { POLLERR, "POLLERR" }, { POLLHUP, "POLLHUP" }, { POLLNVAL, "POLLNVAL" },#endif { 0, NULL },};intsys_poll(tcp)struct tcb *tcp;{ struct pollfd *pollp; if (exiting(tcp)) { int i; int nfds = tcp->u_arg[1]; if (nfds <= 0) { tprintf("%#lx, %d, %ld\n", tcp->u_arg[0], nfds, tcp->u_arg[2]); return 0; } pollp = (struct pollfd *) malloc(nfds * sizeof(*pollp)); if (pollp == NULL) { fprintf(stderr, "sys_poll: no memory\n"); tprintf("%#lx, %d, %ld", tcp->u_arg[0], nfds, tcp->u_arg[2]); return 0; } if (umoven(tcp, tcp->u_arg[0], (nfds * sizeof(*pollp)), (char *) pollp) < 0) { tprintf("%#lx", tcp->u_arg[0]); } else { tprintf("["); for (i = 0; i < nfds; i++) { if (i) tprintf(", "); if (pollp[i].fd < 0) { tprintf("{fd=%d}", pollp[i].fd); continue; } tprintf("{fd=%d, events=", pollp[i].fd); if (!printflags(pollflags, pollp[i].events)) tprintf("0"); if (!syserror(tcp) && pollp[i].revents) { tprintf(", revents="); if (!printflags(pollflags, pollp[i].revents)) tprintf("0"); } tprintf("}"); } tprintf("]"); } tprintf(", %d, ", nfds);#ifdef INFTIM if (tcp->u_arg[2] == INFTIM) tprintf("INFTIM"); else#endif tprintf("%ld", tcp->u_arg[2]); free(pollp); } return 0;}#else /* !HAVE_SYS_POLL_H */intsys_poll(tcp)struct tcb *tcp;{ return 0;}#endif#if !defined(linux) && !defined(FREEBSD)static struct xlat stream_flush_options[] = { { FLUSHR, "FLUSHR" }, { FLUSHW, "FLUSHW" }, { FLUSHRW, "FLUSHRW" },#ifdef FLUSHBAND { FLUSHBAND, "FLUSHBAND" },#endif { 0, NULL },};static struct xlat stream_setsig_flags[] = { { S_INPUT, "S_INPUT" }, { S_HIPRI, "S_HIPRI" }, { S_OUTPUT, "S_OUTPUT" }, { S_MSG, "S_MSG" },#ifdef S_ERROR { S_ERROR, "S_ERROR" },#endif#ifdef S_HANGUP { S_HANGUP, "S_HANGUP" },#endif#ifdef S_RDNORM { S_RDNORM, "S_RDNORM" },#endif#ifdef S_WRNORM { S_WRNORM, "S_WRNORM" },#endif#ifdef S_RDBAND { S_RDBAND, "S_RDBAND" },#endif#ifdef S_WRBAND { S_WRBAND, "S_WRBAND" },#endif#ifdef S_BANDURG { S_BANDURG, "S_BANDURG" },#endif { 0, NULL },};static struct xlat stream_read_options[] = { { RNORM, "RNORM" }, { RMSGD, "RMSGD" }, { RMSGN, "RMSGN" }, { 0, NULL },};static struct xlat stream_read_flags[] = {#ifdef RPROTDAT { RPROTDAT, "RPROTDAT" },#endif#ifdef RPROTDIS { RPROTDIS, "RPROTDIS" },#endif#ifdef RPROTNORM { RPROTNORM, "RPROTNORM" },#endif { 0, NULL },
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -