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

📄 tselect.c

📁 wm PNE 3.3 source code, running at more than vxworks6.x version.
💻 C
字号:
/* $Header: /usr/cvsroot/target/src/wrn/wm/demo/socktest/tselect.c,v 1.1.1.1 2001/11/05 17:49:14 tneale Exp $ *//* * Copyright (C) 1999-2005 Wind River Systems, Inc. * All rights reserved.  Provided under license only. * Distribution or other use of this software is only * permitted pursuant to the terms of a license agreement * from Wind River Systems (and is otherwise prohibited). * Refer to that license agreement for terms of use. *//**************************************************************************** *  Copyright 1998 Integrated Systems, Inc. *  All rights reserved. ****************************************************************************//* * $Log: tselect.c,v $ * Revision 1.1.1.1  2001/11/05 17:49:14  tneale * Tornado shuffle * * Revision 1.3  2001/01/19 22:24:55  paul * Update copyright. * * Revision 1.2  2000/10/20 18:32:36  paul * si.sin_len is only defined for BSD * * Revision 1.1  2000/10/16 19:23:01  paul * Renamed from test_select.c * * Revision 1.5  2000/03/17 00:14:48  meister * Update copyright message * * Revision 1.4  1999/07/30 21:29:47  paul * enhanced test_fail, test_pass * * Revision 1.2  1999/02/18 04:16:12  wes * Socket Merge: new code (socket tests). * * Revision 1.1.2.6  1999/01/06 21:42:48  paul * reworked a bit, test select on tcp sockets * * Revision 1.1.2.5  1998/11/06 23:36:53  paul * rototill to support tcp * *//* [clearcase]modification history-------------------01a,19apr05,job  update copyright notices*/#include "test.h"/* test_sel flags */#define SELR 1#define SELW 2static voidtest_sel(char *proto, char *name, int nfds, int s, int flags,	 int secs, int usecs, int eret, int eerr){  struct timeval tv;  fd_set readfds, *rfdp = 0;  fd_set writefds, *wfdp = 0;  int maxfd = 0;    tv.tv_sec = secs;  tv.tv_usec = usecs;  if (nfds) {    FD_ZERO(&readfds);    FD_ZERO(&writefds);    if (s >= 0) {      FD_SET(s, &readfds);      FD_SET(s, &writefds);    }    if (flags & SELR)      rfdp = &readfds;    if (flags & SELW)      wfdp = &writefds;    maxfd = s + 1;  }  test(proto, name, select(maxfd, rfdp, wfdp, 0, &tv), eret, eerr);}#define test_sel_0(proto, name, secs, usecs) \  test_sel(proto, name, 0, -1, 0, secs, usecs, 0, 0)#define test_sel_r(proto, name, s, secs, usecs, eret, eerr) \  test_sel(proto, name, 1, s, SELR, secs, usecs, eret, eerr)#define test_sel_w(proto, name, s, secs, usecs, eret, eerr) \  test_sel(proto, name, 1, s, SELW, secs, usecs, eret, eerr)#define test_sel_rw(proto, name, s, secs, usecs, eret, eerr) \  test_sel(proto, name, 1, s, SELR|SELW, secs, usecs, eret, eerr)static void test_select_1(int type, char *proto);voidtest_select(int flags){  if (flags & TEST_UDP)    test_select_1(SOCK_DGRAM, "udp");  if (flags & TEST_TCP)    test_select_1(SOCK_STREAM, "tcp");}static voidtest_select_1(int type, char *proto){  int s, i;  struct sockaddr_in snd_si;  char snd_buf[32], rcv_buf[32];    for (i = 0; i < sizeof(snd_buf); ++i)    snd_buf[i] = i;  s = socket(PF_INET, type, 0);  if (s < 0) {    test_fail(proto, "select", "socket");    return;  }  test_sel_0(proto, "select null select, polling", 0, 0);  test_sel_0(proto, "select null select, 10us timeout", 0, 10);    test_sel_0(proto, "select null select, 1s timeout", 1, 0);  i = -1;  if (ioctl(s, FIONBIO, (char *) &i) == -1)    test_fail(proto, "select", "ioctl(FIONBIO)");  memset(&snd_si, 0, sizeof(snd_si));  snd_si.sin_family = AF_INET;#if INSTALL_ATTACHE_SOCKETS_44BSD  snd_si.sin_len = sizeof(snd_si);#endif  snd_si.sin_addr.s_addr = server;  snd_si.sin_port = htons(7);		/* echo */  if ((connect(s, (struct sockaddr *) &snd_si, sizeof(snd_si)) != 0) &&      (errno != EINPROGRESS))    test_fail(proto, "select", "connect");  test_sel_w(proto, "select, connect, polling", s, 0, 0, (type == SOCK_STREAM) ? 0 : 1, 0);  test_sel_w(proto, "select, connect, 5s timeout", s, 5, 0, 1, 0);  if (send(s, snd_buf, sizeof(snd_buf), 0) != sizeof(snd_buf))    test_fail(proto, "select", "send");  test_sel_r(proto, "select, recv, polling", s, 0, 0, 0, 0);  test_sel_r(proto, "select, recv, 5s timeout", s, 5, 0, 1, 0);  if (recv(s, rcv_buf, sizeof(rcv_buf), 0) != sizeof(rcv_buf))    test_fail(proto, "select", "recv");  test_sel_r(proto, "select, empty queue, polling", s, 0, 0, 0, 0);  test_sel_r(proto, "select, empty queue, 5s timeout", s, 5, 0, 0, 0);  close(s);  test_sel_rw(proto, "select on closed descriptor", s, 0, 0, -1, EBADF);}

⌨️ 快捷键说明

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