Browse Source

Hack in WIP Windows socket support

master
Macoy Madson 2 months ago
parent
commit
bd373aa3ba
  1. 27
      src/Network.cake

27
src/Network.cake

@ -1,6 +1,27 @@
;; Network.cake: Provide easy access to the sockets API
(export
(c-import "<string.h>"
"<sys/socket.h>" "<sys/types.h>" "<unistd.h>"
"<netinet/tcp.h>" "<netinet/in.h>" "<netdb.h>")
(comptime-cond
('Windows
(c-import "<string.h>"
"<winsock2.h>" "<stdio.h>"))
(true
(c-import "<string.h>"
"<sys/socket.h>" "<sys/types.h>" "<unistd.h>"
"<netinet/tcp.h>" "<netinet/in.h>" "<netdb.h>")))
(def-type-alias-global socket-type int))
(comptime-cond
('Windows
(import "CHelpers.cake")
(def-c-function-alias close closesocket)
;; TODO: This sucks; I should use dedicated read-socket functions to not break file reads
(defmacro read (socket any buffer any buffer-size any)
(tokenize-push output
(recv (token-splice socket) (type-cast (token-splice buffer) (* char)) (token-splice buffer-size) 0))
(return true))
(defmacro write (socket any buffer any buffer-size any)
(tokenize-push output
(send (token-splice socket) (type-cast (token-splice buffer) (* (const char))) (token-splice buffer-size) 0))
(return true))
(add-static-link-objects "Ws2_32.lib")))

Loading…
Cancel
Save