-
Notifications
You must be signed in to change notification settings - Fork 3
/
Copy pathsocket.c
78 lines (57 loc) · 1.96 KB
/
socket.c
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
/* uSockets is entierly opaque so we can use the real header straight up */
#include "../uWebSockets.js/uWebSockets/uSockets/src/libusockets.h"
#include "internal.h"
#include <stdio.h>
#include <stdlib.h>
#include <stdalign.h>
#include <string.h>
int us_socket_write(int ssl, struct us_socket_t *s, const char *data, int length, int msg_more) {
if (!length) {
return 0;
}
us_internal_socket_context_send_packet(s->context, s->hostSeq, s->hostAck, s->networkIp, s->networkDestinationIp, s->hostPort, s->hostDestinationPort, 1, 0, 0, 0, data, length);
s->hostSeq += length;
/* Send everything */
return length;
}
void us_socket_timeout(int ssl, struct us_socket_t *s, unsigned int seconds) {
if (seconds) {
unsigned short timeout_sweeps = (unsigned short) (0.5f + ((float) seconds) / ((float) LIBUS_TIMEOUT_GRANULARITY));
s->timeout = timeout_sweeps ? timeout_sweeps : 1;
} else {
s->timeout = 0;
}
}
void *us_socket_ext(int ssl, struct us_socket_t *s) {
//printf("socket ext: %p\n", s + 1);
return s + 1;
}
struct us_socket_context_t *us_socket_context(int ssl, struct us_socket_t *s) {
//printf("Socket context: %p\n", s->context);
return s->context;
}
void us_socket_flush(int ssl, struct us_socket_t *s) {
}
void us_socket_shutdown(int ssl, struct us_socket_t *s) {
s->shutdown = 1;
}
int us_socket_is_shut_down(int ssl, struct us_socket_t *s) {
return s->shutdown;
}
int us_socket_is_closed(int ssl, struct us_socket_t *s) {
return s->closed;
}
struct us_socket_t *us_socket_close(int ssl, struct us_socket_t *s) {
if (!us_socket_is_closed(0, s)) {
/* Emit close event */
s = s->context->on_close(s);
}
/* We are now closed */
s->closed = 1;
/* Add us to the close list */
printf("closing socket is not implemented!\n");
return s;
}
void us_socket_remote_address(int ssl, struct us_socket_t *s, char *buf, int *length) {
*length = 0;
}