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

📄 tsendmsg.c

📁 wm PNE 3.3 source code, running at more than vxworks6.x version.
💻 C
字号:
/* $Header: /usr/cvsroot/target/src/wrn/wm/demo/socktest/tsendmsg.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: tsendmsg.c,v $ * Revision 1.1.1.1  2001/11/05 17:49:14  tneale * Tornado shuffle * * Revision 1.4  2001/05/24 20:32:31  paul * CAD-UL compiler is picky. * * Revision 1.3  2001/01/19 22:24:56  paul * Update copyright. * * Revision 1.2  2000/10/27 18:06:26  paul * Some comments should only be made in verbose mode. * * Revision 1.1  2000/10/16 19:23:08  paul * Renamed from test_sendmsg.c * * Revision 1.5  2000/03/17 00:14:49  meister * Update copyright message * * Revision 1.4  1999/07/30 21:29:48  paul * enhanced test_fail, test_pass * * Revision 1.3  1999/06/25 22:52:06  wes * Test large sends. * * Revision 1.2  1999/02/18 04:16:14  wes * Socket Merge: new code (socket tests). * * Revision 1.1.2.3  1999/01/06 21:41:55  paul * added configurable server address * * Revision 1.1.2.2  1998/11/06 23:36:54  paul * rototill to support tcp * *//* [clearcase]modification history-------------------01a,19apr05,job  update copyright notices*/#include "test.h"static char buf0[10] = "0123456789";static char buf1[26] = "abcdefghijklmnopqrstuvwxyz";static char buf2[32] = "................................";static char bigbuf[10240];static void test_sendmsg_1(int type, char *proto);voidtest_sendmsg(int flags){  if (flags & TEST_UDP)    test_sendmsg_1(SOCK_DGRAM, "udp");  if (flags & TEST_TCP)    test_sendmsg_1(SOCK_STREAM, "tcp");}static voidtest_sendmsg_1(int type, char *proto){  int s;  struct sockaddr_in si;  struct iovec iov[10];  struct msghdr msg;  s = socket(PF_INET, type, 0);  if (s < 0) {    test_fail(proto, "sendmsg", "socket");    return;  }  si.sin_family = AF_INET;  si.sin_port = htons(9);  si.sin_addr.s_addr = server;  connect(s, (struct sockaddr *) &si, sizeof(si));  memset(&bigbuf, 0, sizeof(bigbuf));  memset(&msg, 0, sizeof(msg));  msg.msg_iov = iov;  msg.msg_iovlen = 3;  iov[0].iov_base = buf0;  iov[0].iov_len = sizeof(buf0);  iov[1].iov_base = buf1;  iov[1].iov_len = sizeof(buf1);  iov[2].iov_base = buf2;  iov[2].iov_len = sizeof(buf2);  test(proto, "sendmsg null msg",        sendmsg(s, 0, 0),       -1, EFAULT);  msg.msg_iovlen = 0;  test(proto, "sendmsg msg_iovlen=0",       sendmsg(s, &msg, 0),       0, 0);  msg.msg_iovlen = 3;  iov[0].iov_base = 0;  iov[0].iov_len = 0;  msg.msg_iovlen = 1;  test(proto, "sendmsg null iov_base (zero iov_len)",       sendmsg(s, &msg, 0),       0, 0);  iov[0].iov_base = buf0;  iov[0].iov_len = sizeof(buf0);  msg.msg_iovlen = 3;  iov[0].iov_base = 0;  msg.msg_iovlen = 1;  test(proto, "sendmsg null iov_base (non-zero iov_len)",       sendmsg(s, &msg, 0),       -1, EFAULT);  iov[0].iov_base = buf0;  msg.msg_iovlen = 3;  iov[1].iov_len = 0;  test(proto, "sendmsg zero iov_len",       sendmsg(s, &msg, 0),       sizeof(buf0) + sizeof(buf2), 0);  iov[1].iov_len = sizeof(buf1);  test(proto, "sendmsg 0/1/2",       sendmsg(s, &msg, 0),       sizeof(buf0) + sizeof(buf1) + sizeof(buf2), 0);  iov[0].iov_len = iov[1].iov_len = iov[2].iov_len = 1;  test(proto, "sendmsg 1 byte each",       sendmsg(s, &msg, 0),       3, 0);  if (type == SOCK_STREAM)     {      int i;            iov[0].iov_len = sizeof(buf0);      iov[1].iov_base = bigbuf;      iov[1].iov_len = sizeof(bigbuf);      iov[2].iov_len = sizeof(buf2);      test(proto, "really big sendmsg",	   sendmsg(s, &msg, 0),	   10+32+10240, 0);      iov[0].iov_base = bigbuf;      iov[0].iov_len = 970;      iov[1].iov_base = bigbuf;      iov[1].iov_len = sizeof(bigbuf);      iov[2].iov_base = bigbuf;      iov[2].iov_len = 970-540;      test(proto, "another really big sendmsg ",	   sendmsg(s, &msg, 0),	   970+10240+970-540, 0);      /* send bigger than TCP window size.. */      for (i=0; i<10; i++) 	{	  iov[i].iov_base = bigbuf;	  iov[i].iov_len = sizeof(bigbuf);	}      msg.msg_iovlen = 10;            test(proto, "even bigger sendmsg",	   sendmsg(s, &msg, 0),	   10240*10, 0);    }  {    struct linger li = { 1, 60 };    int ret = setsockopt(s, SOL_SOCKET, SO_LINGER, &li, sizeof(li));    if (ret < 0)       if (verbose)	printf("so_linger failed! %d %d\n", ret, errno);  }    close(s);}

⌨️ 快捷键说明

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