Subversion Repositories Kolibri OS

Rev

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

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