⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 xnet.c

📁 OpenSS7 This the fourth public release of the OpenSS7 Master Package. See README in the release for
💻 C
📖 第 1 页 / 共 5 页
字号:
  * Sets the state of the transport endpoint in the user structure to the  * variable state specified.  This is in contrast to the inline version.  @see  * __xnet_u_setstate_const.  */static void__xnet_u_setstate(struct _t_user *user, int state){	user->statef = (1 << state);	switch (state) {	case TS_UNBND:	case TS_WACK_BREQ:		user->state = T_UNBND;		break;	case TS_WACK_UREQ:	case TS_IDLE:	case TS_WACK_CREQ:		user->state = T_IDLE;		break;	case TS_WCON_CREQ:	case TS_WACK_DREQ6:		user->state = T_OUTCON;		break;	case TS_WRES_CIND:	case TS_WACK_CRES:	case TS_WACK_DREQ7:		user->state = T_INCON;		break;	case TS_DATA_XFER:	case TS_WACK_DREQ9:		user->state = T_DATAXFER;		break;	case TS_WIND_ORDREL:	case TS_WACK_DREQ10:		user->state = T_OUTREL;		break;	case TS_WREQ_ORDREL:	case TS_WACK_DREQ11:		user->state = T_INREL;		break;	default:		user->state = T_UNINIT;	}}/** @internal  * @brief Set the current event.  * @param user a pointer to the _t_user structure for this endpoint.  * @param prim the TPI primitive associated with the event.  * @param flags the flags associated with a @c T_OPTDATA_IND primitive.  *   * Sets the current event in the transport endpoint user structure according  * to the current primitive.  */static inline int__xnet_u_setevent(struct _t_user *user, int prim, int flags){	switch ((user->prim = prim)) {	case -1:		return (user->event = T_DATA);	case T_CONN_IND:		return (user->event = T_LISTEN);	case T_CONN_CON:		return (user->event = T_CONNECT);	case T_DISCON_IND:		return (user->event = T_DISCONNECT);	case T_DATA_IND:		return (user->event = T_DATA);	case T_EXDATA_IND:		return (user->event = T_EXDATA);	case T_UNITDATA_IND:		return (user->event = T_DATA);	case T_UDERROR_IND:		return (user->event = T_UDERR);	case T_ORDREL_IND:		return (user->event = T_ORDREL);	case T_OPTDATA_IND:		return (user->event = (flags & T_ODF_EX) ? T_EXDATA : T_DATA);	default:		return (user->event = 0);	}}/** @internal  * @brief Reset (consume) the current event.  * @param user a pointer to the _t_user structure for this endpoint.  *  * Resets (or consumes) the current event.  All event information within the  * specified user structure is reset.  */static void__xnet_u_reset_event(struct _t_user *user){	if (user->event != T_EXDATA || (!user->moresdu && !user->moredat)) {		user->prim = 0;		user->event = 0;		user->ctrl.maxlen = user->ctlmax;		user->ctrl.len = 0;		user->ctrl.buf = user->ctlbuf;		user->data.maxlen = user->datmax;		user->data.len = 0;		user->data.buf = user->datbuf;		user->moredat = 0;		user->moresdu = 0;		user->moreexp = 0;		user->moreedu = 0;		user->moremsg = 0;	} else {		/** When we are clearing an expedited data event, we must revert to an outstanding		   data event. */		user->prim = 0;		user->event = T_DATA;		user->ctrl.maxlen = user->ctlmax;		user->ctrl.len = 0;		user->ctrl.buf = user->ctlbuf;		user->data.maxlen = user->datmax;		user->data.len = 0;		user->data.buf = user->datbuf;		user->moreexp = 0;		user->moreedu = 0;		user->moremsg = 0;	}}static inline int__xnet_u_max_addr(struct _t_user *user){	return (user->info.addr == T_INFINITE		? MAXINT : (user->info.addr >= 0 ? user->info.addr : 0));}static inline int__xnet_u_max_options(struct _t_user *user){	return (user->info.options == T_INFINITE		? MAXINT : (user->info.options >= 0 ? user->info.options : 0));}static inline int__xnet_u_max_tsdu(struct _t_user *user){	return ((user->info.tsdu == T_INFINITE || user->info.tsdu == 0)		? MAXINT : (user->info.tsdu >= 0 ? user->info.tsdu : 0));}static inline int__xnet_u_max_etsdu(struct _t_user *user){	return ((user->info.etsdu == T_INFINITE || user->info.etsdu == 0)		? MAXINT : (user->info.etsdu >= 0 ? user->info.etsdu : 0));}static inline int__xnet_u_max_connect(struct _t_user *user){	return (user->info.connect == T_INFINITE		? MAXINT : (user->info.connect >= 0 ? user->info.connect : 0));}static inline int__xnet_u_max_discon(struct _t_user *user){	return (user->info.discon == T_INFINITE		? MAXINT : (user->info.discon >= 0 ? user->info.discon : 0));}static inline int__xnet_u_max_tidu(struct _t_user *user){	return (user->info.tidu == T_INFINITE		? MAXINT : (user->info.tidu >= 0 ? user->info.tidu : 0));}/*   Forward declarations  */static int __xnet_t_getmsg(int fd, struct strbuf *ctrl, struct strbuf *data, int *flagsp);static int __xnet_t_putmsg(int fd, struct strbuf *ctrl, struct strbuf *data, int flags);static int __xnet_t_putpmsg(int fd, struct strbuf *ctrl, struct strbuf *data, int band, int flags);static int __xnet_t_ioctl(int fd, int cmd, void *arg);static int __xnet_t_strioctl(int fd, int cmd, void *arg, size_t arglen);int __xnet_t_peek(int fd);#if 0int __xnet_t_accept(int fd, int resfd, const struct t_call *call);int __xnet_t_addleaf(int fd, int leafid, struct netbuf *addr);char *__xnet_t_alloc(int fd, int type, int fields);int __xnet_t_bind(int fd, const struct t_bind *req, struct t_bind *ret);int __xnet_t_close(int fd);int __xnet_t_connect(int fd, const struct t_call *sndcall, struct t_call *rcvcall);int __xnet_t_free(void *ptr, int type);int __xnet_t_getinfo(int fd, struct t_info *info);int __xnet_t_getstate(int fd);int __xnet_t_listen(int fd, struct t_call *call);int __xnet_t_look(int fd);int __xnet_t_open(const char *path, int oflag, struct t_info *info);int __xnet_t_optmgmt(int fd, const struct t_optmgmt *req, struct t_optmgmt *ret);int __xnet_t_rcv(int fd, char *buf, unsigned int nbytes, int *flags);int __xnet_t_rcvconnect(int fd, struct t_call *call);int __xnet_t_rcvdis(int fd, struct t_discon *discon);int __xnet_t_rcvleafchange(int fd, struct t_leaf_status *change);int __xnet_t_rcvrel(int fd);int __xnet_t_rcvreldata(int fd, struct t_discon *discon);int __xnet_t_rcvopt(int fd, struct t_unitdata *optdata, int *flags);int __xnet_t_rcvudata(int fd, struct t_unitdata *unitdata, int *flags);int __xnet_t_rcvv(int fd, struct t_iovec *iov, unsigned int iovcount, int *flags);int __xnet_t_rcvvudata(int fd, struct t_unitdata *unitdata, struct t_iovec *iov,		       unsigned int iovcount, int *flags);int __xnet_t_removeleaf(int fd, int leafid, int reason);int __xnet_t_snd(int fd, char *buf, unsigned int nbytes, int flags);int __xnet_t_snddis(int fd, const struct t_call *call);int __xnet_t_sndrel(int fd);int __xnet_t_sndreldata(int fd, struct t_discon *discon);int __xnet_t_sndopt(int fd, const struct t_unitdata *optdata, int flags);int __xnet_t_sndvopt(int fd, const struct t_unitdata *optdata, const struct t_iovec *iov,		     unsigned int iovcount, int flags);int __xnet_t_sndudata(int fd, const struct t_unitdata *unitdata);int __xnet_t_sndv(int fd, const struct t_iovec *iov, unsigned int iovcount, int flags);int __xnet_t_sndvudata(int fd, struct t_unitdata *unitdata, struct t_iovec *iov,		       unsigned int iovcount);int __xnet_t_sysconf(int name);int __xnet_t_unbind(int fd);const char *__xnet_t_strerror(int errnum);#endif#if 0int __xnet_t_accept_r(int fd, int resfd, const struct t_call *call);int __xnet_t_addleaf_r(int fd, int leafid, struct netbuf *addr);char *__xnet_t_alloc_r(int fd, int type, int fields);int __xnet_t_bind_r(int fd, const struct t_bind *req, struct t_bind *ret);int __xnet_t_close_r(int fd);int __xnet_t_connect_r(int fd, const struct t_call *sndcall, struct t_call *rcvcall);int __xnet_t_getinfo_r(int fd, struct t_info *info);int __xnet_t_getstate_r(int fd);int __xnet_t_listen_r(int fd, struct t_call *call);int __xnet_t_look_r(int fd);int __xnet_t_open_r(const char *path, int oflag, struct t_info *info);int __xnet_t_optmgmt_r(int fd, const struct t_optmgmt *req, struct t_optmgmt *ret);int __xnet_t_rcv_r(int fd, char *buf, unsigned int nbytes, int *flags);int __xnet_t_rcvconnect_r(int fd, struct t_call *call);int __xnet_t_rcvdis_r(int fd, struct t_discon *discon);int __xnet_t_rcvleafchange_r(int fd, struct t_leaf_status *change);int __xnet_t_rcvrel_r(int fd);int __xnet_t_rcvreldata_r(int fd, struct t_discon *discon);int __xnet_t_rcvopt_r(int fd, struct t_unitdata *optdata, int *flags);int __xnet_t_rcvudata_r(int fd, struct t_unitdata *unitdata, int *flags);int __xnet_t_rcvv_r(int fd, struct t_iovec *iov, unsigned int iovcount, int *flags);int __xnet_t_rcvvudata_r(int fd, struct t_unitdata *unitdata, struct t_iovec *iov,			 unsigned int iovcount, int *flags);int __xnet_t_removeleaf_r(int fd, int leafid, int reason);int __xnet_t_snd_r(int fd, char *buf, unsigned int nbytes, int flags);int __xnet_t_snddis_r(int fd, const struct t_call *call);int __xnet_t_sndrel_r(int fd);int __xnet_t_sndreldata_r(int fd, struct t_discon *discon);int __xnet_t_sndopt_r(int fd, const struct t_unitdata *optdata, int flags);int __xnet_t_sndvopt_r(int fd, const struct t_unitdata *optdata, const struct t_iovec *iov,		       unsigned int iovcount, int flags);int __xnet_t_sndudata_r(int fd, const struct t_unitdata *unitdata);int __xnet_t_sndv_r(int fd, const struct t_iovec *iov, unsigned int iovcount, int flags);int __xnet_t_sndvudata_r(int fd, struct t_unitdata *unitdata, struct t_iovec *iov,			 unsigned int iovcount);int __xnet_t_unbind_r(int fd);#endif/** @internal  * @brief A version of getmsg with XTI errors.  * @param fd a file descriptor representing the transport endpoint.  * @param ctrl a pointer to a strbuf structure returning the control part of  * the message.  * @param data a pointer to a strbuf structure returning the data part of the  * message.  * @param flagsp a pointer to an integer returning the flags associated with  * the retrieved message.  *   * This is the same as getmsg(2) with the exception that XTI errors are  * returned.  *  * @since Sun Dec 21 19:23:52 MST 2003  *  * @return When __xnet_t_getmsg() succeeds, it returns zero (0); when it  * fails, it returns -1.  *  * @par Errors  * __xnet_t_getmsg() can return the following XTI errors:  *  * @retval TBADF  * #fd is not associated with a file open for reading or is a directory  * rather than a file.  * @retval TNODATA  * @c O_NONBLOCK was set on open(2) or with fcntl(2) and no data is available  * to be read.  * @retval TSYSERR  * A Linux system error occured and the error number  is in errno(3).  */static int__xnet_t_getmsg(int fd, struct strbuf *ctrl, struct strbuf *data, int *flagsp){	int ret;	if ((ret = getmsg(fd, ctrl, data, flagsp)) >= 0)		return (ret);	t_errno = TSYSERR;	switch (errno) {	case EISDIR:	case EBADF:		t_errno = TBADF;		break;	case EFAULT:	case ENODEV:	case ENOSTR:	case EIO:	case EINVAL:		break;	case EAGAIN:		t_errno = TNODATA;		return (0);	case EINTR:	case ENOSR:	case EBADMSG:		break;	}	return (-1);}/**  * @internal  * @brief A version of putmsg with XTI errors.  * @param fd a file descriptor representing the transport endpoint.  * @param ctrl a pointer to a strbuf structure describing the control part of  * the message.  * @param data a pointer to a strbuf structure describing the data part of the  * message.  * @param flags a flag integer describing the nature of the message.  *   * This is the same as putmsg(2) with the exception that XTI errors are  * returned.  */static __hot int__xnet_t_putmsg(int fd, struct strbuf *ctrl, struct strbuf *data, int flags){	int ret;	if ((ret = putmsg(fd, ctrl, data, flags)) >= 0)		return (ret);	t_errno = TSYSERR;	switch (errno) {	case EAGAIN:		t_errno = TFLOW;		break;	case EISDIR:	case EBADF:		t_errno = TBADF;		break;	case EFAULT:	case EINTR:	case EINVAL:	case EIO:	case ENODEV:	case ENOSR:	case ENOSTR:	case ENXIO:	case ERANGE:		break;	}	return (-1);}/**  * @internal  * @brief A version of putpmsg with XTI errors.  * @param fd a file descriptor representing the transport endpoint.  * @param ctrl a pointer to a strbuf structure describing the control part of  * the message.  * @param data a pointer to a strbuf structure describing the data part of the  * message.  * @param band a band number describing the band for the message.  * @param flags a flag integer describing the nature of the message.  *  * This is the same as putpmsg(2) with the exception that XTI errors are  * returned.  */static int__xnet_t_putpmsg(int fd, struct strbuf *ctrl, struct strbuf *data, int band, int flags){	int ret;	if ((ret = putpmsg(fd, ctrl, data, band, flags)) != -1)		return (ret);	t_errno = TSYSERR;	switch (errno) {	case EAGAIN:		t_errno = TFLOW;		break;	case EISDIR:	case EBADF:		t_errno = TBADF;		break;	case EFAULT:	case EINTR:	case EINVAL:	case EIO:	case ENODEV:	case ENOSR:	case ENOSTR:	case ENXIO:	case ERANGE:		break;	}	return (-1);}static __hot int__xnet_t_getdata(int fd, struct strbuf *udata, int expect){	struct _t_user *user = _t_fds[fd];	int ret, flag = 0;	union T_primitives *p = (typeof(p)) user->ctlbuf;	if (likely(user->event == T_DATA) || likely(user->event == T_EXDATA)) {		if (unlikely(!(user->event & expect)))			goto done;		if (unlikely(user->data.len < 1))			goto getmoredata;		udata->len = min(udata->maxlen, user->data.len);		memcpy(udata->buf, user->data.buf, udata->len);		user->data.buf += udata->len;		user->data.len -= udata->len;	} else if (user->event == 0) {		__xnet_u_reset_event(user);	      getmoredata:		user->data.maxlen = min(udata->maxlen, user->datmax);		user->data.len = 0;		user->data.buf = udata->buf;		if ((ret = __xnet_t_getmsg(fd, &user->ctrl, &user->data, &flag)) < 0)			goto error;		if (user->ctrl.len < 0)			user->ctrl.len = 0;		if (user->data.len < 0)			user->data.len = 0;		udata->len = user->data.len;		if (ret & MORECTL)			goto cleanup;		if (flag != 0 || flag == RS_HIPRI)			goto tsync;		if (user->ctrl.len || user->data.len) {			if (user->event == 0 || user->ctrl.len > 0)				__xnet_u_setevent(user, user->ctrl.len ? p->type : -1, 0);			/* 			   There is a little extra handling for data indications */

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -