"Fossies" - the Fresh Open Source Software Archive

Member "stress-ng-0.09.56/test/test-sendmmsg.c" (15 Mar 2019, 2240 Bytes) of package /linux/privat/stress-ng-0.09.56.tar.xz:


As a special service "Fossies" has tried to format the requested source page into HTML format using (guessed) C and C++ source code syntax highlighting (style: standard) with prefixed line numbers and code folding option. Alternatively you can here view or download the uninterpreted source code file. See also the last Fossies "Diffs" side-by-side code changes report for "test-sendmmsg.c": 0.09.52_vs_0.09.54.

    1 /*
    2  * Copyright (C) 2013-2019 Canonical, Ltd.
    3  *
    4  * This program is free software; you can redistribute it and/or
    5  * modify it under the terms of the GNU General Public License
    6  * as published by the Free Software Foundation; either version 2
    7  * of the License, or (at your option) any later version.
    8  *
    9  * This program is distributed in the hope that it will be useful,
   10  * but WITHOUT ANY WARRANTY; without even the implied warranty of
   11  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
   12  * GNU General Public License for more details.
   13  *
   14  * You should have received a copy of the GNU General Public License
   15  * along with this program; if not, write to the Free Software
   16  * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
   17  *
   18  * This code is a complete clean re-write of the stress tool by
   19  * Colin Ian King <colin.king@canonical.com> and attempts to be
   20  * backwardly compatible with the stress tool by Amos Waterland
   21  * <apw@rossby.metr.ou.edu> but has more stress tests and more
   22  * functionality.
   23  *
   24  */
   25 
   26 #define _GNU_SOURCE
   27 
   28 #include <netinet/ip.h>
   29 #include <stdio.h>
   30 #include <stdlib.h>
   31 #include <string.h>
   32 #include <sys/types.h>
   33 #include <sys/socket.h>
   34 
   35 int main(void)
   36 {
   37     int sockfd;
   38     struct sockaddr_in addr;
   39     struct mmsghdr msg_hdr[2];
   40     struct iovec msg_iov1[2], msg_iov2[3];
   41 
   42     (void)memset(&addr, 0, sizeof(addr));
   43     (void)memset(&msg_iov1, 0, sizeof(msg_iov1));
   44     (void)memset(&msg_iov2, 0, sizeof(msg_iov2));
   45     (void)memset(&msg_hdr, 0, sizeof(msg_hdr));
   46 
   47     sockfd = socket(AF_INET, SOCK_DGRAM, 0);
   48     if (sockfd < 0)
   49         return 1;
   50 
   51     addr.sin_family = AF_INET;
   52     addr.sin_addr.s_addr = htonl(INADDR_LOOPBACK);
   53     addr.sin_port = htons(9999);
   54     if (connect(sockfd, (struct sockaddr *) &addr, sizeof(addr)) == -1)
   55         return 1;
   56 
   57     msg_iov1[0].iov_base = "1";
   58     msg_iov1[0].iov_len = 1;
   59     msg_iov1[1].iov_base = "2";
   60     msg_iov1[1].iov_len = 1;
   61 
   62     msg_iov2[0].iov_base = "3";
   63     msg_iov2[0].iov_len = 1;
   64     msg_iov2[0].iov_base = "4";
   65     msg_iov2[0].iov_len = 1;
   66     msg_iov2[0].iov_base = "5";
   67     msg_iov2[0].iov_len = 1;
   68 
   69     msg_hdr[0].msg_hdr.msg_iov = msg_iov1;
   70     msg_hdr[0].msg_hdr.msg_iovlen = 2;
   71     msg_hdr[1].msg_hdr.msg_iov = msg_iov2;
   72     msg_hdr[1].msg_hdr.msg_iovlen = 3;
   73 
   74     return sendmmsg(sockfd, msg_hdr, 2, 0);
   75 }