CoreFW  Diff

Differences From Artifact [cad757af38]:

To Artifact [ba08fae5df]:


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

#include "stream.h"
#include "tcpsocket.h"

struct CFWTCPSocket {
	CFWStream stream;
	int fd;
	bool eof;
};

static ssize_t
sock_read(void *ptr, void *buf, size_t len)
{
	CFWTCPSocket *sock = ptr;
	ssize_t ret;

	if ((ret = recv(sock->fd, buf, len, 0)) == 0)
		sock->eof = true;

	return ret;
}

static bool
sock_write(void *ptr, const void *buf, size_t len)
{
	CFWTCPSocket *sock = ptr;
	ssize_t ret;

	if ((ret = send(sock->fd, buf, len, 0)) < len)
		return false;

	return true;
}

static bool
sock_eof(void *ptr)
{
	CFWTCPSocket *sock = ptr;

	return sock->eof;
}

static void
sock_close(void *ptr)
{
	CFWTCPSocket *sock = ptr;

	if (sock->fd != -1)
		close(sock->fd);
}

static struct cfw_stream_ops stream_ops = {
	.read = sock_read,
	.write = sock_write,
	.eof = sock_eof,
	.close = sock_close
};

static bool
ctor(void *ptr, va_list args)
{
	CFWTCPSocket *sock = ptr;

	cfw_stream->ctor(ptr, args);

	sock->fd = -1;
	sock->stream.ops = &stream_ops;
	sock->eof = false;

	return true;
}

static void
dtor(void *ptr)
{







|









|

















|



|














|












|







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

#include "stream.h"
#include "tcpsocket.h"

struct CFWTCPSocket {
	CFWStream stream;
	int fd;
	bool at_end;
};

static ssize_t
sock_read(void *ptr, void *buf, size_t len)
{
	CFWTCPSocket *sock = ptr;
	ssize_t ret;

	if ((ret = recv(sock->fd, buf, len, 0)) == 0)
		sock->at_end = true;

	return ret;
}

static bool
sock_write(void *ptr, const void *buf, size_t len)
{
	CFWTCPSocket *sock = ptr;
	ssize_t ret;

	if ((ret = send(sock->fd, buf, len, 0)) < len)
		return false;

	return true;
}

static bool
sock_at_end(void *ptr)
{
	CFWTCPSocket *sock = ptr;

	return sock->at_end;
}

static void
sock_close(void *ptr)
{
	CFWTCPSocket *sock = ptr;

	if (sock->fd != -1)
		close(sock->fd);
}

static struct cfw_stream_ops stream_ops = {
	.read = sock_read,
	.write = sock_write,
	.at_end = sock_at_end,
	.close = sock_close
};

static bool
ctor(void *ptr, va_list args)
{
	CFWTCPSocket *sock = ptr;

	cfw_stream->ctor(ptr, args);

	sock->fd = -1;
	sock->stream.ops = &stream_ops;
	sock->at_end = false;

	return true;
}

static void
dtor(void *ptr)
{