63 int actual = recv(
c, (
char *)buf, (
int)bufsize, 0);
71 *bytesread = (size_t)actual;
94 int actual = send(
c, (
char *)buf, (
int)bufsize, 0);
102 *byteswritten = (size_t)actual;
124 return write(buf, bufsize, byteswritten);
133 size_t bufferSize = bufsize + buf2size;
141 if (!
write(buf, bufsize, byteswritten))
145 size_t buf2written = 0;
146 if (!
write(buf2, buf2size, &buf2written))
150 *byteswritten += buf2written;
155 memcpy(buffer, buf, bufsize);
156 memcpy(buffer + bufsize, buf2, buf2size);
158 int actual = send(
c, buffer, (
int)bufferSize, 0);
168 *byteswritten = (size_t)actual;
185 char *buffer = (
char *)malloc(size);
283 char *hostname = strdup(name);
285 char *portstr = strstr(hostname,
":");
295 int port = atoi(portstr);
303 bool result =
open(hostname, port);
324 if (WSAStartup(MAKEWORD(2,0), &wsaData))
337 phe = gethostbyname(host);
340 memcpy(&addr.sin_addr, phe->h_addr,
sizeof(addr.sin_addr));
344 addr.sin_addr.s_addr = inet_addr(host);
346 if (addr.sin_addr.s_addr == INADDR_NONE)
354 addr.sin_port = htons(port);
355 if (connect(
c, (
struct sockaddr *) &addr,
sizeof(addr)) == -1)
461 hostname = strdup(name);
462 portstr = strstr(hostname,
":");
471 port = atoi(portstr);
492 int so_reuseaddr =
true;
496 if (WSAStartup(MAKEWORD(2,0), &wsaData))
508 setsockopt(
s, SOL_SOCKET, SO_REUSEADDR, (
char *)&so_reuseaddr,
509 sizeof(so_reuseaddr));
511 memset(&addr, 0,
sizeof (addr));
513 addr.sin_port = htons(port);
518 addr.sin_addr.s_addr = inet_addr(
"127.0.0.1");
519 if (bind(
s, (
struct sockaddr *) &addr,
sizeof(addr)) == -1)
544 int sz =
sizeof(addr);
551 SOCKET client = accept(
s, (
struct sockaddr *) &addr, &sz);
620 int nameLen =
sizeof(addr);
621 rc = getpeername(
c, (
struct sockaddr *)&addr, &nameLen);
626 if (strcmp(
"127.0.0.1", inet_ntoa(addr.sin_addr)) != 0)
SysServerConnection(SysServerStream *s, int socket)
SysServerConnection * connect()
void returnMessageBuffer(void *)
char * getMessageBuffer(size_t size)
bool write(void *buf, size_t bufsize, size_t *byteswritten)
bool read(void *buf, size_t bufsize, size_t *bytesread)
struct sockaddr_in sockaddr_in