Skip to content

Commit

Permalink
lib: introduce socket library
Browse files Browse the repository at this point in the history
Introduce a new socket module which provides bindings for the BSD sockets
API to ucode scripts.

Example usage:

    import * as socket from 'socket';

    let sk = socket.create(socket.AF_INET, socket.SOCK_STREAM);
    sk.connect("192.168.1.1", 80);
    sk.send("GET / HTTP/1.0\r\n\r\n");
    print(sk.recv(4096));
    sk.close();

Signed-off-by: Jo-Philipp Wich <[email protected]>
  • Loading branch information
jow- committed Apr 20, 2024
1 parent cfe137b commit a4d4536
Show file tree
Hide file tree
Showing 2 changed files with 2,793 additions and 0 deletions.
8 changes: 8 additions & 0 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,7 @@ option(RESOLV_SUPPORT "NS resolve plugin support" ON)
option(STRUCT_SUPPORT "Struct plugin support" ON)
option(ULOOP_SUPPORT "Uloop plugin support" ${DEFAULT_ULOOP_SUPPORT})
option(LOG_SUPPORT "Log plugin support" ON)
option(SOCKET_SUPPORT "Socket plugin support" ON)

set(LIB_SEARCH_PATH "${CMAKE_INSTALL_PREFIX}/lib/ucode/*.so:${CMAKE_INSTALL_PREFIX}/share/ucode/*.uc:./*.so:./*.uc" CACHE STRING "Default library search path")
string(REPLACE ":" "\", \"" LIB_SEARCH_DEFINE "${LIB_SEARCH_PATH}")
Expand Down Expand Up @@ -266,6 +267,13 @@ if(LOG_SUPPORT)
endif()
endif()

if(SOCKET_SUPPORT)
set(LIBRARIES ${LIBRARIES} socket_lib)
add_library(socket_lib MODULE lib/socket.c)
set_target_properties(socket_lib PROPERTIES OUTPUT_NAME socket PREFIX "")
target_link_options(socket_lib PRIVATE ${UCODE_MODULE_LINK_OPTIONS})
endif()

if(UNIT_TESTING)
enable_testing()
add_definitions(-DUNIT_TESTING)
Expand Down
Loading

0 comments on commit a4d4536

Please sign in to comment.