fehQlibs
27
Qlibs
Loading...
Searching...
No Matches
fehQlibs-27
src
socket_tcp.c
Go to the documentation of this file.
1
#include <sys/types.h>
2
#include <sys/param.h>
3
#include <sys/socket.h>
4
#include <netinet/in.h>
5
#include <errno.h>
6
#include "
close.h
"
/* better use unistd.h ? */
7
#include "
ndelay.h
"
8
#include "
socket_if.h
"
9
#include "
error.h
"
10
11
#ifndef EAFNOSUPPORT
12
#define EAFNOSUPPORT EINVAL
13
#endif
14
21
22
int
socket_tcp4
(
void
)
23
{
24
int
s;
25
26
s = socket(AF_INET,SOCK_STREAM,0);
27
if
(s != -1)
28
if
(
ndelay_on
(s) == -1) {
close
(s);
return
-1; }
29
30
return
s;
31
}
32
33
int
socket_tcp6
(
void
)
34
{
35
int
s;
36
37
s = socket(AF_INET6,SOCK_STREAM,0);
38
if
(s != -1)
39
if
(
ndelay_on
(s) == -1) {
close
(s);
return
-1; }
40
41
return
s;
42
}
43
44
int
socket_tcp
(
void
)
45
{
46
int
s;
47
48
s = socket(AF_INET6,SOCK_STREAM,0);
49
if
(s == -1)
50
if
(errno == EINVAL || errno ==
EAFNOSUPPORT
|| errno ==
EPROTO
|| errno == EPROTONOSUPPORT)
51
s = socket(AF_INET,SOCK_STREAM,0);
52
53
if
(s != -1)
54
if
(
ndelay_on
(s) == -1) {
close
(s);
return
-1; }
55
56
return
s;
57
}
58
59
int
socket_tcpnodelay
(
int
s)
60
{
61
int
opt = 1;
62
return
setsockopt(s,IPPROTO_TCP,1,&opt,
sizeof
(opt));
/* 1 == TCP_NODELAY */
63
}
error.h
EPROTO
#define EPROTO
Definition
error.h:7
socket_if.h
ndelay.h
ndelay_on
int ndelay_on(int)
Definition
ndelay.c:16
close.h
close
int close(int __fd)
EAFNOSUPPORT
#define EAFNOSUPPORT
Definition
socket_tcp.c:12
socket_tcp
int socket_tcp(void)
Definition
socket_tcp.c:44
socket_tcp6
int socket_tcp6(void)
Definition
socket_tcp.c:33
socket_tcp4
int socket_tcp4(void)
Definition
socket_tcp.c:22
socket_tcpnodelay
int socket_tcpnodelay(int s)
Definition
socket_tcp.c:59
Generated on Tue May 27 2025 21:48:00 for fehQlibs by
1.13.2