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

📄 ioctlsock.c

📁 用于嵌入式系统的TCP/IP协议栈
💻 C
字号:
/***********************************************************************//*                                                                     *//*   Module:  ioctlsock.c                                              *//*   Release: 2001.3                                                   *//*   Version: 99.0                                                     *//*   Purpose: ioctlsocket() implementation                             *//*                                                                     *//*---------------------------------------------------------------------*//*                                                                     *//*               Copyright 1999, Blunk Microsystems                    *//*                      ALL RIGHTS RESERVED                            *//*                                                                     *//*   Licensees have the non-exclusive right to use, modify, or extract *//*   this computer program for software development at a single site.  *//*   This program may be resold or disseminated in executable format   *//*   only. The source code may not be redistributed or resold.         *//*                                                                     *//***********************************************************************/#include "../tcp_ipp.h"/***********************************************************************//* Global Function Definitions                                         *//***********************************************************************//***********************************************************************//* ioctlsocket: Set/get socket's I/O mode                              *//*                                                                     *//***********************************************************************/int ioctlsocket(int s, int request, void *argp){  int rc = 0;  SOCKET sock = &Socks[s - 1];#if OS_PARM_CHECK  /*-------------------------------------------------------------------*/  /* Verify protocol has been initialized.                             */  /*-------------------------------------------------------------------*/  if (!Net.Initialized)  {    NetError(NULL, ENETDOWN);    return -1;  }  /*-------------------------------------------------------------------*/  /* Check for valid socket ID.                                        */  /*-------------------------------------------------------------------*/  if (InvalidHandle(s))  {    NetError(NULL, ENOTSOCK);    return -1;  }  /*-------------------------------------------------------------------*/  /* Verify that argp is not NULL.                                     */  /*-------------------------------------------------------------------*/  if (argp == NULL)  {    NetError(sock, EFAULT);    return -1;  }#endif  /*-------------------------------------------------------------------*/  /* Gain exclusive socket API access and stack internals access.      */  /*-------------------------------------------------------------------*/  if (semPend(sock->api_access, WAIT_FOREVER))  {    NetError(NULL, ENOTSOCK);    return -1;  }  semPend(Net.IntSem, WAIT_FOREVER);  /*-------------------------------------------------------------------*/  /* Determine the particular request made.                            */  /*-------------------------------------------------------------------*/  switch (request)  {    case FIONBIO:      /*---------------------------------------------------------------*/      /* Set non-blocking flag iff argument is TRUE.                   */      /*---------------------------------------------------------------*/      if (*(int *)argp)        sock->flags |= SF_NONBLKNG;      else        sock->flags &= ~SF_NONBLKNG;      break;    case FIONREAD:      /*---------------------------------------------------------------*/      /* Output receive buffer count, queued datagram size, or zero.   */      /*---------------------------------------------------------------*/      if (sock->type == SOCK_STREAM)        *(int *)argp = sock->rb_count;      else if (sock->rq_head)        *(int *)argp = sock->rq_head->app_len;      else        *(int *)argp = 0;      break;    case SIOCATMARK:      /*---------------------------------------------------------------*/      /* Verify that socket type is TCP.                               */      /*---------------------------------------------------------------*/      if (sock->type != SOCK_STREAM)      {        NetError(sock, EOPNOTSUPP);        rc = -1;      }      /*---------------------------------------------------------------*/      /* Output TRUE iff out-of-band data is available at socket.      */      /*---------------------------------------------------------------*/      else        *(int *)argp = sock->flags & SF_OOB_DATA;      break;    default:      /*---------------------------------------------------------------*/      /* Invalid request code.                                         */      /*---------------------------------------------------------------*/      NetError(sock, EINVAL);      rc = -1;      break;  }  /*-------------------------------------------------------------------*/  /* Release exclusive API and internals access and return result.     */  /*-------------------------------------------------------------------*/  semPost(sock->api_access);  semPost(Net.IntSem);  return rc;}

⌨️ 快捷键说明

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