source: mainline/uspace/srv/net/tcp/test.c@ b7fd2a0

lfn serial ticket/834-toolchain-update topic/msim-upgrade topic/simplify-dev-export
Last change on this file since b7fd2a0 was b7fd2a0, checked in by Jiří Zárevúcky <zarevucky.jiri@…>, 7 years ago

Use errno_t in all uspace and kernel code.

Change type of every variable, parameter and return value that holds an
<errno.h> constant to either errno_t (the usual case), or sys_errno_t
(some places in kernel). This is for the purpose of self-documentation,
as well as for type-checking with a bit of type definition hackery.

Although this is a massive commit, it is a simple text replacement, and thus
is very easy to verify. Simply do the following:

`
git checkout <this commit's hash>
git reset HEAD
git add .
tools/srepl '\berrno_t\b' int
git add .
tools/srepl '\bsys_errno_t\b' sysarg_t
git reset
git diff
`

While this doesn't ensure that the replacements are correct, it does ensure
that the commit doesn't do anything except those replacements. Since errno_t
is typedef'd to int in the usual case (and sys_errno_t to sysarg_t), even if
incorrect, this commit cannot change behavior.

  • Property mode set to 100644
File size: 3.6 KB
RevLine 
[c5808b41]1/*
[2f19103]2 * Copyright (c) 2015 Jiri Svoboda
[c5808b41]3 * All rights reserved.
4 *
5 * Redistribution and use in source and binary forms, with or without
6 * modification, are permitted provided that the following conditions
7 * are met:
8 *
9 * - Redistributions of source code must retain the above copyright
10 * notice, this list of conditions and the following disclaimer.
11 * - Redistributions in binary form must reproduce the above copyright
12 * notice, this list of conditions and the following disclaimer in the
13 * documentation and/or other materials provided with the distribution.
14 * - The name of the author may not be used to endorse or promote products
15 * derived from this software without specific prior written permission.
16 *
17 * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
18 * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
19 * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
20 * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
21 * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
22 * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
23 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
24 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
25 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
26 * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
27 */
28
29/** @addtogroup tcp
30 * @{
31 */
32
33/**
[032bbe7]34 * @file Internal TCP test
[c5808b41]35 */
36
37#include <async.h>
38#include <errno.h>
39#include <stdio.h>
[88a6819]40#include <fibril.h>
[32105348]41#include <str.h>
[c5808b41]42#include "tcp_type.h"
[762b48a]43#include "ucall.h"
[c5808b41]44
45#include "test.h"
46
[d9ce049]47#define RCV_BUF_SIZE 64
48
[b7fd2a0]49static errno_t test_srv(void *arg)
[c5808b41]50{
51 tcp_conn_t *conn;
[2f19103]52 inet_ep2_t epp;
[d9ce049]53 char rcv_buf[RCV_BUF_SIZE + 1];
54 size_t rcvd;
55 xflags_t xflags;
[c5808b41]56
57 printf("test_srv()\n");
[2f19103]58
59 inet_ep2_init(&epp);
60
61 inet_addr(&epp.local.addr, 127, 0, 0, 1);
62 epp.local.port = 80;
63
64 inet_addr(&epp.remote.addr, 127, 0, 0, 1);
65 epp.remote.port = 1024;
66
[eea65f4]67 printf("S: User open...\n");
[2f19103]68 tcp_uc_open(&epp, ap_passive, 0, &conn);
[7cf7ded]69 conn->name = (char *) "S";
[d9ce049]70
71 while (true) {
[eea65f4]72 printf("S: User receive...\n");
[d9ce049]73 tcp_uc_receive(conn, rcv_buf, RCV_BUF_SIZE, &rcvd, &xflags);
[8c7a054]74 if (rcvd == 0) {
[6896409c]75 printf("S: End of data reached.\n");
[8c7a054]76 break;
77 }
[d9ce049]78 rcv_buf[rcvd] = '\0';
[eea65f4]79 printf("S: User received %zu bytes '%s'.\n", rcvd, rcv_buf);
[d9ce049]80
81 async_usleep(1000*1000*2);
82 }
[8c7a054]83
[7cf7ded]84 async_usleep(/*10**/1000*1000);
[6e88fea]85
[eea65f4]86 printf("S: User close...\n");
[6e88fea]87 tcp_uc_close(conn);
88
[8c7a054]89 printf("test_srv() terminating\n");
[88a6819]90 return 0;
[c5808b41]91}
92
[b7fd2a0]93static errno_t test_cli(void *arg)
[c5808b41]94{
95 tcp_conn_t *conn;
[2f19103]96 inet_ep2_t epp;
[32105348]97 const char *msg = "Hello World!";
[c5808b41]98
99 printf("test_cli()\n");
[2f19103]100
101 inet_ep2_init(&epp);
102
103 inet_addr(&epp.local.addr, 127, 0, 0, 1);
104 epp.local.port = 1024;
105
106 inet_addr(&epp.remote.addr, 127, 0, 0, 1);
107 epp.remote.port = 80;
[8c7a054]108
[c5808b41]109 async_usleep(1000*1000*3);
[eea65f4]110 printf("C: User open...\n");
[2f19103]111 tcp_uc_open(&epp, ap_active, 0, &conn);
[7cf7ded]112 conn->name = (char *) "C";
[32105348]113
114 async_usleep(1000*1000*10);
[eea65f4]115 printf("C: User send...\n");
[32105348]116 tcp_uc_send(conn, (void *)msg, str_size(msg), 0);
[8c7a054]117
[1812a0d]118 async_usleep(1000*1000*20/**20*2*/);
[eea65f4]119 printf("C: User close...\n");
[8c7a054]120 tcp_uc_close(conn);
[88a6819]121
122 return 0;
[c5808b41]123}
124
125void tcp_test(void)
126{
[88a6819]127 fid_t srv_fid;
128 fid_t cli_fid;
[c5808b41]129
130 printf("tcp_test()\n");
131
[1812a0d]132 async_usleep(1000*1000);
133
[a4ee3ab2]134 if (0) {
[88a6819]135 srv_fid = fibril_create(test_srv, NULL);
136 if (srv_fid == 0) {
137 printf("Failed to create server fibril.\n");
[a4ee3ab2]138 return;
139 }
[88a6819]140
141 fibril_add_ready(srv_fid);
[c5808b41]142 }
143
[04cd242]144 if (0) {
[88a6819]145 cli_fid = fibril_create(test_cli, NULL);
146 if (cli_fid == 0) {
147 printf("Failed to create client fibril.\n");
[04cd242]148 return;
149 }
[88a6819]150
151 fibril_add_ready(cli_fid);
[c5808b41]152 }
153}
154
155/**
156 * @}
157 */
Note: See TracBrowser for help on using the repository browser.