ProductPromotion
Logo

C Programming

made by https://0x3d.site

GitHub - silentbicycle/socket99: Wrapper library for the BSD sockets API with a nicer C99 interface
Wrapper library for the BSD sockets API with a nicer C99 interface - silentbicycle/socket99
Visit Site

GitHub - silentbicycle/socket99: Wrapper library for the BSD sockets API with a nicer C99 interface

GitHub - silentbicycle/socket99: Wrapper library for the BSD sockets API with a nicer C99 interface

A wrapper library for the BSD sockets API.

Why?

This library trades the series of getaddrinfo, socket, connect, bind, listen, etc. functions and their convoluted, casted arguments for just one function that takes two structs (configuration and output). By creatively using C99's "designated initializers", the configuration struct works rather like a configuration key/value hash; the output struct contains either the socket file descriptor or error information.

The sheer generality of the BSD sockets API also makes it rather unwieldy. While the sockets API can be used for a lot of esoteric things, there's no reason common use cases such as opening a TCP socket to a given host and port should take dozens of lines of code.

License

socket99 is released under the ISC license.

Requirements

This depends on C99 and a POSIX environment. You've got one of those lying around somewhere, right?

Basic Usage

Look at the fields in struct socket99_config listen in socket99.h, call socket99_open with a pointer to a configuration struct using the C99 designated initializer syntax. Only a few of the fields will be used, such as:

socket99_config cfg = {
    .host = "127.0.0.1",
    .port = 8080,
    .server = true,
    .nonblocking = true,
};

for a non-blocking TCP server that listens to 127.0.0.1. This function will return a bool for whether the socket was successfully created, and the result struct argument will be modified to contain a status code and either a file descriptor (on success) or error information on failure:

socket99_result res;   // result output in this struct
bool ok = socket99_open(&cfg, &res);

The configuration and result structs are no longer needed after the result struct's file descriptor has been saved / errors are handled, so both structs can be stack-allocated.

For more usage examples, look at test_socket99.c.

Running the tests

To run the tests:

$ make test

Note that the tests create a couple short-lived sockets on port 8080, and if that port is already in use, the tests will fail. To run the tests on a different port, set the PORT environment variable:

$ env PORT=12345 make test

Supported Use Cases

  • Client and server

  • TCP, UDP, and Unix domain sockets (either stream and datagram)

  • Blocking and nonblocking

  • IPV4, IPv6, and "don't care"

  • setsockopt(2) options

Future Development

Capturing other common use cases for sockets would be good.

More Resources
to explore the angular.

mail [email protected] to add your project or resources here 🔥.

Related Articles
to learn about angular.

FAQ's
to learn more about Angular JS.

mail [email protected] to add more queries here 🔍.

More Sites
to check out once you're finished browsing here.

0x3d
https://www.0x3d.site/
0x3d is designed for aggregating information.
NodeJS
https://nodejs.0x3d.site/
NodeJS Online Directory
Cross Platform
https://cross-platform.0x3d.site/
Cross Platform Online Directory
Open Source
https://open-source.0x3d.site/
Open Source Online Directory
Analytics
https://analytics.0x3d.site/
Analytics Online Directory
JavaScript
https://javascript.0x3d.site/
JavaScript Online Directory
GoLang
https://golang.0x3d.site/
GoLang Online Directory
Python
https://python.0x3d.site/
Python Online Directory
Swift
https://swift.0x3d.site/
Swift Online Directory
Rust
https://rust.0x3d.site/
Rust Online Directory
Scala
https://scala.0x3d.site/
Scala Online Directory
Ruby
https://ruby.0x3d.site/
Ruby Online Directory
Clojure
https://clojure.0x3d.site/
Clojure Online Directory
Elixir
https://elixir.0x3d.site/
Elixir Online Directory
Elm
https://elm.0x3d.site/
Elm Online Directory
Lua
https://lua.0x3d.site/
Lua Online Directory
C Programming
https://c-programming.0x3d.site/
C Programming Online Directory
C++ Programming
https://cpp-programming.0x3d.site/
C++ Programming Online Directory
R Programming
https://r-programming.0x3d.site/
R Programming Online Directory
Perl
https://perl.0x3d.site/
Perl Online Directory
Java
https://java.0x3d.site/
Java Online Directory
Kotlin
https://kotlin.0x3d.site/
Kotlin Online Directory
PHP
https://php.0x3d.site/
PHP Online Directory
React JS
https://react.0x3d.site/
React JS Online Directory
Angular
https://angular.0x3d.site/
Angular JS Online Directory