This repository has been archived by the owner on Nov 8, 2022. It is now read-only.
/
net.h
123 lines (79 loc) · 3.61 KB
/
net.h
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
/*
Copyright (C) 2008 Joseph Jordan <joe.ftpii@psychlaw.com.au>
This software is provided 'as-is', without any express or implied warranty.
In no event will the authors be held liable for any damages arising from
the use of this software.
Permission is granted to anyone to use this software for any purpose,
including commercial applications, and to alter it and redistribute it
freely, subject to the following restrictions:
1.The origin of this software must not be misrepresented; you must not
claim that you wrote the original software. If you use this software in a
product, an acknowledgment in the product documentation would be
appreciated but is not required.
2.Altered source versions must be plainly marked as such, and must not be
misrepresented as being the original software.
3.This notice may not be removed or altered from any source distribution.
*/
/****************************************************************************
* WiiUFtpServer
* 2021-12-05:Laf111:V7-0
***************************************************************************/
#ifndef _NET_H_
#define _NET_H_
#include <coreinit/thread.h>
#include "ftp.h"
#ifdef __cplusplus
extern "C"{
#endif
#include <stdio.h>
#include <stdint.h>
#include <stdbool.h>
#include <sys/socket.h>
#define UNUSED __attribute__((unused))
#ifndef MIN
#define MIN(x, y) ((x) < (y) ? (x) : (y))
#endif
#ifndef MAX
#define MAX(x, y) ((x) > (y) ? (x) : (y))
#endif
// number max of concurrents transfer slots
#define NB_SIMULTANEOUS_TRANSFERS 8
// Timeouts for retrying the calls to the network API
#define NET_RETRY_TIME_STEP_MILLISECS 3900
// socket extra definitions -------------------------------------------------------------------------
#define SO_RUSRBUF 0x10000 // enable userspace socket buffer
#define SO_NOSLOWSTART 0x4000 // suppress slowstart
#define TCP_NOACKDELAY 0x2002 // suppress delayed ACKs
#define TCP_MAXSEG 0x2003 // set maximum segment size
#define TCP_NODELAY 0x2004 // suppress TCP delay
// --------------------------------------------------------------------------------------------------
// user buffers (socket and file) -------------------------------------------------------------------
#define UNSCALED_BUFFER_SIZE (8*1024)
// setsockopt send buffer size (the value will be doubled by the system when setsockopt)
// 131072 bytes (128KB = 128 x 1024) = 16*(8*1024)
#define SOCKET_BUFFER_SIZE (16*UNSCALED_BUFFER_SIZE)
#define UL_BUFFER_SIZE (4*SOCKET_BUFFER_SIZE)
#define DL_BUFFER_SIZE (2*SOCKET_BUFFER_SIZE)
// socket memory buffer size = (2*sndBuffSize+2*rcvBuffSize)
#define SOMEMOPT_BUFFER_SIZE (4*SOCKET_BUFFER_SIZE)
// --------------------------------------------------------------------------------------------------
int32_t initialize_network();
void finalize_network();
int32_t network_socket(uint32_t domain,uint32_t type,uint32_t protocol);
int32_t network_bind(int32_t s,struct sockaddr *name,int32_t namelen);
int32_t network_listen(int32_t s,uint32_t backlog);
int32_t network_accept(int32_t s,struct sockaddr *addr,int32_t *addrlen);
int32_t network_connect(int32_t s,struct sockaddr *,int32_t);
int32_t network_read(int32_t s,void *mem,int32_t len);
int32_t network_close(int32_t s);
uint32_t network_gethostip();
int32_t set_blocking(int32_t s, bool blocking);
int32_t network_close_blocking(int32_t s);
int32_t send_exact(int32_t s, char *buf, int32_t length);
int32_t send_from_file(int32_t data_socket, connection_t* connection);
int32_t recv_to_file(int32_t data_socket, connection_t* connection);
uint32_t getNbFilesTransferred();
#ifdef __cplusplus
}
#endif
#endif /* _NET_H_ */