Commit 933c8fa9c18e22f1dbf1faff9e87ebcbeac70302

Thomas de Grivel 2024-07-26T18:50:05

wip sockets

diff --git a/http/socket_buf.c b/http/socket_buf.c
index 253a5b8..0062749 100644
--- a/http/socket_buf.c
+++ b/http/socket_buf.c
@@ -43,6 +43,13 @@ s_socket_buf * socket_buf_init (s_socket_buf *sb, t_socket sockfd,
   }
   tmp.buf_rw.r.user_ptr = sb;
   tmp.buf_rw.w.user_ptr = sb;
+  if (! buf_rw_fd_open(&tmp.buf_rw, sockfd)) {
+    err_puts("socket_buf_init: buf_rw_fd_open");
+    assert(! "socket_buf_init: buf_rw_fd_open");
+    close(sockfd);
+    buf_rw_clean(&tmp.buf_rw);
+    return NULL;
+  }
   tmp.sockfd = sockfd;
   tmp.addr = socket_addr_new_copy(addr, addr_len);
   if (! tmp.addr) {
@@ -83,20 +90,6 @@ s_socket_buf * socket_buf_init_accept (s_socket_buf *sb, p_socket listening)
     close(sockfd);
     return NULL;
   }
-  if (! buf_rw_init_alloc(&tmp.buf_rw, BUF_SIZE)) {
-    err_puts("socket_buf_init_accept: buf_rw_init_alloc");
-    assert(! "socket_buf_init_accept: buf_rw_init_alloc");
-    close(sockfd);
-    return NULL;
-  }
-  if (! buf_rw_fd_open(&tmp.buf_rw, sockfd)) {
-    err_puts("socket_buf_init_accept: buf_rw_fd_open");
-    assert(! "socket_buf_init_accept: buf_rw_fd_open");
-    close(sockfd);
-    buf_rw_clean(&tmp.buf_rw);
-    return NULL;
-  }
-  tmp.sockfd = sockfd;
   *sb = tmp;
   return sb;
 }
diff --git a/lib/kc3/0.1/buf.kc3 b/lib/kc3/0.1/buf.kc3
index f83d453..3e495df 100644
--- a/lib/kc3/0.1/buf.kc3
+++ b/lib/kc3/0.1/buf.kc3
@@ -19,4 +19,6 @@ defmodule Buf do
 
   def parse_tag = cfn Tag "kc3_buf_parse_tag" (Buf, Result)
 
+  def write_str = cfn Sw "buf_write_str" (Buf, Str)
+
 end
diff --git a/lib/kc3/0.1/ekc3.so b/lib/kc3/0.1/ekc3.so
index 2d95dd8..39ab92d 120000
--- a/lib/kc3/0.1/ekc3.so
+++ b/lib/kc3/0.1/ekc3.so
@@ -1 +1 @@
-../../../ekc3/.libs/libekc3.so.0.0
\ No newline at end of file
+../../../ekc3/.libs/libekc3_debug.so.0.0
\ No newline at end of file
diff --git a/lib/kc3/0.1/http.so b/lib/kc3/0.1/http.so
index d0160ff..a4d4f0c 120000
--- a/lib/kc3/0.1/http.so
+++ b/lib/kc3/0.1/http.so
@@ -1 +1 @@
-../../../http/.libs/libkc3_http.so.0.0
\ No newline at end of file
+../../../http/.libs/libkc3_http_debug.so.0.0
\ No newline at end of file
diff --git a/lib/kc3/0.1/socket.kc3 b/lib/kc3/0.1/socket.kc3
index 886a02b..8004844 100644
--- a/lib/kc3/0.1/socket.kc3
+++ b/lib/kc3/0.1/socket.kc3
@@ -4,12 +4,8 @@ defmodule Socket do
 
   dlopen(__DIR__ + "http.so")
 
-  def accept = cfn Socket.Buf "socket_buf_init_accept" (Result, Socket)
-
   def close = cfn Void "socket_close" (Socket)
 
-  def connect = cfn Socket.Buf "socket_buf_init_connect" (Result, Str, Str)
-
   def listen = cfn Socket "socket_init_listen" (Result, Str, Str)
 
 end
diff --git a/lib/kc3/0.1/socket/buf.kc3 b/lib/kc3/0.1/socket/buf.kc3
index 7b0bc52..3162979 100644
--- a/lib/kc3/0.1/socket/buf.kc3
+++ b/lib/kc3/0.1/socket/buf.kc3
@@ -7,6 +7,10 @@ defmodule Socket.Buf do
 
   dlopen(__DIR__ + "../http.so")
 
+  def accept = cfn Socket.Buf "socket_buf_init_accept" (Result, Socket)
+
   def close = cfn Void "socket_buf_clean" (Socket.Buf)
 
+  def connect = cfn Socket.Buf "socket_buf_init_connect" (Result, Str, Str)
+
 end
diff --git a/test/http/04_server_request.kc3 b/test/http/04_server_request.kc3
index f72c8b7..98de671 100644
--- a/test/http/04_server_request.kc3
+++ b/test/http/04_server_request.kc3
@@ -1,10 +1,11 @@
 quote server = Socket.listen("localhost", "58000")
 server = Socket.listen("localhost", "58000")
-# quote client = Socket.connect("localhost", "58000")
-# client = Socket.connect("localhost", "58000")
+quote client = Socket.Buf.connect("localhost", "58000")
+client = Socket.Buf.connect("localhost", "58000")
 quote server_client = Socket.accept(server)
-server_client = Socket.accept(server)
-
+server_client = Socket.Buf.accept(server)
+quote Buf.write_str(client.buf_rw.w, "GET / HTTP/1.0\r\n\r\n")
+Buf.write_str(client.buf_rw.w, "GET / HTTP/1.0\r\n\r\n")
 quote Socket.Buf.close(client)
 Socket.Buf.close(client)
 quote Socket.Buf.close(server_client)