Subversion Repositories Kolibri OS

Rev

Rev 8537 | Go to most recent revision | Show entire file | Regard whitespace | Details | Blame | Last modification | View Log | RSS feed

Rev 8537 Rev 8538
Line 1... Line 1...
1
#ifndef __SOCKET_H__
1
#ifndef __SOCKET_H__
2
#define __SOCKET_H__
2
#define __SOCKET_H__
Line 3... Line 3...
3
 
3
 
4
#include 
-
 
Line 5... Line 4...
5
#include 
4
#include 
6
 
5
 
7
// Socket Types
6
// Socket Types
8
#define SOCK_STREAM 1
7
#define SOCK_STREAM 1
Line 53... Line 52...
53
 
52
 
54
//Socket options
53
//Socket options
55
#define SO_BINDTODEVICE (1<<9)
54
#define SO_BINDTODEVICE (1<<9)
Line -... Line 55...
-
 
55
#define SO_NONBLOCK (1<<31)
-
 
56
 
-
 
57
// Error Codes
-
 
58
#define ENOBUFS      1
-
 
59
#define EINPROGRESS  2
-
 
60
#define EOPNOTSUPP   4
-
 
61
#define EWOULDBLOCK  6
-
 
62
#define ENOTCONN     9
-
 
63
#define EALREADY     10
-
 
64
#define EINVALUE     11
-
 
65
#define EMSGSIZE     12
-
 
66
#define ENOMEM       18
-
 
67
#define EADDRINUSE   20
-
 
68
#define ECONNREFUSED 61
-
 
69
#define ECONNRESET   52
-
 
70
#define EISCONN      56
-
 
71
#define ETIMEDOUT    60
-
 
72
#define ECONNABORTED 53
56
#define SO_NONBLOCK (1<<31)
73
 
-
 
74
 
Line 57... Line 75...
57
 
75
#define PORT(X) (X<<8)
58
#define PORT(X) (X<<8)
76
int err_code;
59
 
77
 
60
#pragma pack(push,1)
78
#pragma pack(push,1)
Line 78... Line 96...
78
static inline int socket(int domain, int type, int protocol)
96
static inline int socket(int domain, int type, int protocol)
79
{
97
{
80
    int socket;
98
    int socket;
81
    asm volatile(
99
    asm volatile(
82
    "int $0x40"
100
    "int $0x40"
83
    :"=b"(errno), "=a"(socket)
101
    :"=b"(err_code), "=a"(socket)
84
    :"a"(75), "b"(0), "c"(domain), "d"(type), "S"(protocol)
102
    :"a"(75), "b"(0), "c"(domain), "d"(type), "S"(protocol)
85
    );
103
    );
86
    return socket;
104
    return socket;
87
}
105
}
Line 88... Line 106...
88
 
106
 
89
static inline int close(int socket)
107
static inline int close(int socket)
90
{
108
{
91
    int status;
109
    int status;
92
    asm volatile(
110
    asm volatile(
93
    "int $0x40"
111
    "int $0x40"
94
    :"=b"(errno), "=a"(status)
112
    :"=b"(err_code), "=a"(status)
95
    :"a"(75), "b"(1), "c"(socket)
113
    :"a"(75), "b"(1), "c"(socket)
96
    );
114
    );
97
    return status;
115
    return status;
Line 98... Line 116...
98
}
116
}
99
 
117
 
100
static inline int bind(int socket, const struct sockaddr *addres, int addres_len)
118
static inline int bind(int socket, const struct sockaddr *addres, int addres_len)
101
{
119
{
102
    int status;
120
    int status;
103
    asm volatile(
121
    asm volatile(
104
    "int $0x40"
122
    "int $0x40"
105
    :"=b"(errno), "=a"(status)
123
    :"=b"(err_code), "=a"(status)
106
    :"a"(75), "b"(2), "c"(socket), "d"(addres), "S"(addres_len)
124
    :"a"(75), "b"(2), "c"(socket), "d"(addres), "S"(addres_len)
107
    );
125
    );
Line 108... Line 126...
108
    return status;
126
    return status;
109
}
127
}
110
 
128
 
111
static inline int listen(int socket, int backlog)
129
static inline int listen(int socket, int backlog)
112
{
130
{
113
    int status;
131
    int status;
114
    asm volatile(
132
    asm volatile(
115
    "int $0x40"
133
    "int $0x40"
116
    :"=b"(errno), "=a"(status)
134
    :"=b"(err_code), "=a"(status)
117
    :"a"(75), "b"(3), "c"(socket), "d"(backlog)
135
    :"a"(75), "b"(3), "c"(socket), "d"(backlog)
Line 118... Line 136...
118
    );
136
    );
119
    return status;
137
    return status;
120
}
138
}
121
 
139
 
122
static inline int connect(int socket, const struct sockaddr* address, int socket_len)
140
static inline int connect(int socket, const struct sockaddr* address, int socket_len)
123
{
141
{
124
    int status;
142
    int status;
125
    asm volatile(
143
    asm volatile(
126
    "int $0x40"
144
    "int $0x40"
127
    :"=b"(errno), "=a"(status)
145
    :"=b"(err_code), "=a"(status)
Line 128... Line 146...
128
    :"a"(75), "b"(4), "c"(socket), "d"(address), "S"(socket_len)
146
    :"a"(75), "b"(4), "c"(socket), "d"(address), "S"(socket_len)
129
    );
147
    );
130
    return status;
148
    return status;
131
}
149
}
132
 
150
 
133
static inline int accept(int socket, const struct sockaddr *address, int address_len)
151
static inline int accept(int socket, const struct sockaddr *address, int address_len)
134
{
152
{
135
    int new_socket;
153
    int new_socket;
136
    asm volatile(
154
    asm volatile(
137
    "int $0x40"
155
    "int $0x40"
Line 138... Line 156...
138
    :"=b"(errno), "=a"(new_socket)
156
    :"=b"(err_code), "=a"(new_socket)
139
    :"a"(75), "b"(5), "c"(socket), "d"(address), "S"(address_len)
157
    :"a"(75), "b"(5), "c"(socket), "d"(address), "S"(address_len)
140
    );
158
    );
141
    return new_socket;
159
    return new_socket;
142
}
160
}
143
 
161
 
144
static inline int send(int socket, const void *message, size_t msg_len, int flag)
162
static inline int send(int socket, const void *message, size_t msg_len, int flag)
145
{
163
{
146
    int status;
164
    int status;
147
    asm volatile(
165
    asm volatile(
Line 148... Line 166...
148
    "int $0x40"
166
    "int $0x40"
149
    :"=b"(errno), "=a"(status)
167
    :"=b"(err_code), "=a"(status)
150
    :"a"(75), "b"(6), "c"(socket), "d"(message), "S"(msg_len), "D"(flag)
168
    :"a"(75), "b"(6), "c"(socket), "d"(message), "S"(msg_len), "D"(flag)
151
    );
169
    );
152
    return status;
170
    return status;
153
}
171
}
154
 
172
 
155
static inline int recv(int socket, void *buffer, size_t buff_len, int flag)
173
static inline int recv(int socket, void *buffer, size_t buff_len, int flag)
156
{
174
{
157
    int status;
175
    int status;
Line 158... Line 176...
158
    asm volatile(
176
    asm volatile(
159
    "int $0x40"
177
    "int $0x40"
160
    :"=b"(errno), "=a"(status)
178
    :"=b"(err_code), "=a"(status)
161
    :"a"(75), "b"(7), "c"(socket), "d"(buffer), "S"(buff_len), "D"(flag)
179
    :"a"(75), "b"(7), "c"(socket), "d"(buffer), "S"(buff_len), "D"(flag)
162
    );
180
    );
163
    return status;
181
    return status;
164
}
182
}
165
 
183
 
166
static inline int setsockopt(int socket,const optstruct* opt)
184
static inline int setsockopt(int socket,const optstruct* opt)
167
{
185
{
Line 168... Line 186...
168
    int status;
186
    int status;
169
    asm volatile(
187
    asm volatile(
170
        "int $0x40"
188
        "int $0x40"
171
        :"=b"(errno), "=a"(status)
189
        :"=b"(err_code), "=a"(status)
172
        :"a"(75), "b"(8), "c"(socket),"d"(opt)
190
        :"a"(75), "b"(8), "c"(socket),"d"(opt)
173
    );
191
    );
174
    return status;
192
    return status;
175
}
193
}
176
 
194
 
177
static inline int getsockopt(int socket, optstruct* opt)
195
static inline int getsockopt(int socket, optstruct* opt)
Line 190... Line 208...
190
    asm volatile(
208
    asm volatile(
191
        "int $0x40"
209
        "int $0x40"
192
        :"=b"(*socket2), "=a"(*socket1)
210
        :"=b"(*socket2), "=a"(*socket1)
193
        :"a"(75), "b"(10)
211
        :"a"(75), "b"(10)
194
    ); 
212
    ); 
195
    errno=*socket2;
213
    err_code=*socket2;
196
    return *socket1;
214
    return *socket1;
197
}
215
}
198
#endif
216
#endif