on master help sign in
Update the windows RTS files and consolidate the headers

No need to have two sets of headers if we move the includes to the C file where they belong.

commitd16d418d6deff8805f975bf7b33991a34885f842 authorniklas <niklas@mm.st> dateSun 18 May 2014, 12:24 (12 years ago) parentd581842
7 files changed+40−88
rts/Makefile+1−3 rts/idris_net.c+11−1 rts/idris_net.h−10 rts/windows/idris_net.c+15−4 rts/windows/idris_net.h−45 rts/windows/idris_stdfgn.c+13−1 rts/windows/idris_stdfgn.h−24
rts/Makefile+1−3
@@ -3,16 +3,14 @@ include ../config.mk
33OBJS = idris_rts.o idris_heap.o idris_gc.o idris_gmp.o idris_bitstring.o \
44 idris_opts.o idris_stats.o mini-gmp.o
55HDRS = idris_rts.h idris_heap.h idris_gc.h idris_gmp.h idris_bitstring.h \
6− idris_opts.h idris_stats.h mini-gmp.h
6+ idris_opts.h idris_stats.h mini-gmp.h idris_stdfgn.h idris_net.h
77CFLAGS:=-fPIC $(CFLAGS)
88CFLAGS += $(GMP_INCLUDE_DIR) $(GMP)
99
1010ifeq ($(OS), windows)
1111 OBJS += windows/idris_stdfgn.o windows/idris_net.o
12− HDRS += windows/idris_stdfgn.h windows/idris_net.h
1312else
1413 OBJS += idris_stdfgn.o idris_net.o
15− HDRS += idris_stdfgn.h idris_net.h
1614endif
1715
1816LIBTARGET = libidris_rts.a
rts/idris_net.c+11−1
@@ -1,9 +1,19 @@
11// C-Side of the Idris network library
22// (C) Simon Fowler, 2014
33// MIT Licensed. Have fun!
4−#include "idris_net.h"
4+#include <errno.h>
5+#include <netdb.h>
6+#include <stdbool.h>
7+#include <stdlib.h>
8+#include <stdio.h>
9+#include <string.h>
10+#include <sys/types.h>
11+#include <sys/socket.h>
12+#include <netinet/in.h>
513#include <arpa/inet.h>
614
15+#include "idris_net.h"
16+
717void* idrnet_malloc(int size) {
818 return malloc(size);
919}
rts/idris_net.h−10
@@ -1,16 +1,6 @@
11#ifndef IDRISNET_H
22#define IDRISNET_H
33
4−#include <errno.h>
5−#include <netdb.h>
6−#include <stdbool.h>
7−#include <stdlib.h>
8−#include <stdio.h>
9−#include <string.h>
10−#include <sys/types.h>
11−#include <sys/socket.h>
12−#include <netinet/in.h>
13−
144typedef struct idrnet_recv_result {
155 int result;
166 void* payload;
rts/windows/idris_net.c+15−4
@@ -1,7 +1,7 @@
11// C-Side of the Idris network library
22// (C) Simon Fowler, 2014
33// MIT Licensed. Have fun!
4−#include "idris_net.h"
4+#include "../idris_net.h"
55
66#include <errno.h>
77#include <stdbool.h>
@@ -11,6 +11,12 @@
1111#include <Winsock2.h>
1212#include <Ws2tcpip.h>
1313
14+
15+// inet_ntop isn't defined in the old mingw delivered with GHC,
16+// so put the prototype here, cribbed from a newer version of it
17+WINSOCK_API_LINKAGE LPCSTR WSAAPI InetNtopA(INT Family, PVOID pAddr,
18+ LPSTR pStringBuf, size_t StringBufSize);
19+
1420static int socket_inited = 0;
1521static WSADATA wsa_data;
1622
@@ -22,12 +28,17 @@ void idrnet_free(void* ptr) {
2228 free(ptr);
2329}
2430
25−static int check_init()
31+static void clean_sockets(void) {
32+ WSACleanup();
33+}
34+
35+static int check_init(void)
2636{
2737 if (!socket_inited) {
2838 int result = WSAStartup(MAKEWORD(2, 2), &wsa_data);
2939 if (result == NO_ERROR) {
3040 socket_inited = 1;
41+ atexit(clean_sockets);
3142 }
3243 }
3344 return socket_inited;
@@ -104,7 +115,7 @@ int idrnet_sockaddr_family(void* sockaddr) {
104115char* idrnet_sockaddr_ipv4(void* sockaddr) {
105116 struct sockaddr_in* addr = (struct sockaddr_in*) sockaddr;
106117 char* ip_addr = (char*) malloc(sizeof(char) * INET_ADDRSTRLEN);
107− inet_ntop(AF_INET, &(addr->sin_addr), ip_addr, INET_ADDRSTRLEN);
118+ InetNtopA(AF_INET, &(addr->sin_addr), ip_addr, INET_ADDRSTRLEN);
108119 return ip_addr;
109120}
110121
@@ -139,7 +150,7 @@ int idrnet_send_buf(int sockfd, void* data, int len) {
139150
140151void* idrnet_recv(int sockfd, int len) {
141152 if (!check_init()) {
142− return -1;
153+ return NULL;
143154 }
144155 idrnet_recv_result* res_struct =
145156 (idrnet_recv_result*) malloc(sizeof(idrnet_recv_result));
rts/windows/idris_net.hdeleted−45
@@ -1,45 +0,0 @@
1−#ifndef IDRISNET_H
2−#define IDRISNET_H
3−
4−
5−typedef struct idrnet_recv_result {
6− int result;
7− void* payload;
8−} idrnet_recv_result;
9−
10−// Memory management functions
11−void* idrnet_malloc(int size);
12−void idrnet_free(void* ptr);
13−
14−// Gets value of errno
15−int idrnet_errno();
16−
17−// Bind
18−int idrnet_bind(int sockfd, int family, int socket_type, char* host, int port);
19−
20−// Connect
21−int idrnet_connect(int sockfd, int family, int socket_type, char* host, int port);
22−
23−// Accessor functions for struct_sockaddr
24−int idrnet_sockaddr_family(void* sockaddr);
25−char* idrnet_sockaddr_ipv4(void* sockaddr);
26−void* idrnet_create_sockaddr();
27−
28−// Accept
29−int idrnet_accept(int sockfd, void* sockaddr);
30−
31−// Send
32−int idrnet_send(int sockfd, char* data);
33−int idrnet_send_buf(int sockfd, void* data, int len);
34−
35−// Receive
36−// Creates a result structure containing result and payload
37−void* idrnet_recv(int sockfd, int len);
38−// Receives directly into a buffer
39−int idrnet_recv_buf(int sockfd, void* buf, int len);
40−
41−// Receive structure accessors
42−int idrnet_get_recv_res(void* res_struct);
43−void* idrnet_get_recv_payload(void* res_struct);
44−void idrnet_free_recv_struct(void* res_struct);
45−#endif
rts/windows/idris_stdfgn.c+13−1
@@ -1,7 +1,10 @@
1−#include "idris_stdfgn.h"
1+#include "../idris_stdfgn.h"
22#include "../idris_rts.h"
3+#include "../idris_gc.h"
4+
35#include <fcntl.h>
46#include <stdio.h>
7+#include <time.h>
58
69extern char** environ;
710
@@ -61,3 +64,12 @@ void* idris_stdin() {
6164char* getEnvPair(int i) {
6265 return *(environ + i);
6366}
67+
68+int idris_time() {
69+ time_t t = time(NULL);
70+ return (int)t;
71+}
72+
73+void idris_forceGC(void* vm) {
74+ idris_gc((VM*)vm);
75+}
rts/windows/idris_stdfgn.hdeleted−24
@@ -1,24 +0,0 @@
1−#ifndef _IDRISSTDFGN_H
2−#define _IDRISSTDFGN_H
3−
4−// A collection of useful standard functions to be used by the prelude.
5−
6−void putStr(char* str);
7−//char* readStr();
8−
9−void* fileOpen(char* f, char* mode);
10−void fileClose(void* h);
11−int fileEOF(void* h);
12−int fileError(void* h);
13−void fputStr(void*h, char* str);
14−
15−void* do_popen(const char* cmd, const char* mode);
16−int fpoll(void* h);
17−
18−int idris_eqPtr(void* x, void* y);
19−int isNull(void* ptr);
20−void* idris_stdin();
21−
22−char* getEnvPair(int i);
23−
24−#endif