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

📄 listen.c

📁 用于嵌入式系统的TCP/IP协议栈
💻 C
字号:
/***********************************************************************//*                                                                     *//*   Module:  listen.c                                                 *//*   Release: 2001.3                                                   *//*   Version: 99.0                                                     *//*   Purpose: listen() 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"/***********************************************************************//* Symbol Definitions                                                  *//***********************************************************************/#define MAX_BACKLOG     5/***********************************************************************//* Global Function Definitions                                         *//***********************************************************************//***********************************************************************//*      listen: Prepare socket to wait for active TCP connection       *//*                                                                     *//*      Inputs: s = socket identifier                                  *//*              backlog = maximum listen queue size                    *//*                                                                     *//*     Returns: 0 if no errors, else -1 with errno set to error code   *//*                                                                     *//***********************************************************************/int listen(int s, int backlog){  int rc;  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 backlog is in allowed range.                          */  /*-------------------------------------------------------------------*/  if ((backlog < 1) || (backlog > MAX_BACKLOG))  {    NetError(sock, EINVAL);    return -1;  }  /*-------------------------------------------------------------------*/  /* Verify that socket type is TCP.                                   */  /*-------------------------------------------------------------------*/  if (sock->type != SOCK_STREAM)  {    NetError(sock, EOPNOTSUPP);    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);  /*-------------------------------------------------------------------*/  /* Check if socket has not been bound.                               */  /*-------------------------------------------------------------------*/  if (sock->local.sin_port == 0)  {    NetError(sock, EINVAL);    rc = -1;  }  /*-------------------------------------------------------------------*/  /* Else check if socket is unconnected.                              */  /*-------------------------------------------------------------------*/  else if (sock->flags & SF_CONNECTED)  {    NetError(sock, EISCONN);    rc = -1;  }  /*-------------------------------------------------------------------*/  /* Else set socket state to LISTEN and initialize backlog.           */  /*-------------------------------------------------------------------*/  else  {    sock->state = SS_LISTEN;    sock->lis_backlog = backlog;    rc = 0;  }  /*-------------------------------------------------------------------*/  /* Release exclusive API and internals access. Return status code.   */  /*-------------------------------------------------------------------*/  semPost(sock->api_access);  semPost(Net.IntSem);  return rc;}

⌨️ 快捷键说明

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