Skip to content

Latest commit

 

History

1 Commit

Folders and files

NameName
Last commit message
Last commit date
 
 
 
 
 
 
 
 

Repository files navigation

LibSocket

A Small and easy to use C Socket library for binding different operating systems together. No more going out of your way to hunt things down No more complainaing about larger than needed libraries. Problem solved. Functionality is based off libraries such as CPython's socketmodule and c-ares for ideas and problem solving so that nothing new needs re-inventing.

What functions does this small library implement?

Nothing major just yet besides just libsocket_setblocking most of these are linked to single functions however in the future, more functionality will be added in if an OS needs compensation for. While some code might be dissapointing to see in the eyes of some users, this library does have OS support for multiple operating systems with the inclusions of some header files already taken care of for you.

The Current API is as follows however more is to come of this library in the future.

#ifdef _WIN32
typedef uintptr_t socket_t;
#else
typedef int socket_t;
#endif /* WIN32*/

typedef struct sockaddr sockaddr_t;

socket_t libsocket_socket(int data, int type, int protocol);
int libsocket_close(socket_t fd);
int libsocket_setsockopt(socket_t fd, int level, int opt, const void* val, size_t val_len);
int libsocket_connect(socket_t fd, const sockaddr_t* addr, size_t addr_len);
int libsocket_send(socket_t fd, const void* buf, size_t length, int flags);
int libsocket_recv(socket_t fd, const void* buf, size_t length, int flags);
int libsocket_bind(socket_t fd, const sockaddr_t* addr, size_t addr_len);
int libsocket_setblocking(socket_t fd, int block);

int libsocket_inet_ntop(sockaddr_t *src, int family, const void* dst, size_t size);
int libsocket_inet_pton(sockaddr_t* src, void* dst);

int libsocket_init();
void libsocket_cleanup();

const char* libsocket_get_version();

What it was made for.

  • No Nonsense code or additional implemenations, no extras, no other objects added in. It's just sockets. You can make it synchronous or work async when using your own selectors or eventloops. It is fast and is written in C as a lightweight project. All you need is the libsocket.h header file and libsocket.c file. The reason it's not simply a single header file however is the desire for performance. On Windows nothing needs to be worried about but for others LIBSOCKET_HAS_SYS_IOCTL is a bit of a problem to figure out but is entirely optional to use. If you have the ioctl function on your OS defining this macro before adding in your code should work.

  • You get what you came for, author happy, developer happy, software happy, user happy.

  • A License that helps the developers feel a little less guilty when needing to rip a few lines of code for some other thing. We've all been guilty for doing so believe me, I've done it too many times. This library does too so that guessing games do not end in a bitter disaster.

  • A Project that is easy to build upon. While this isn't a header only system this was done by design and it prevents slow performance when compiling or running or having to deal with weird or unwanted macros popping from out of nowhere.

  • Everything is written in C. No stingy languages, paywalls or C++ hiding behind something. The header file does define __cplusplus however if exporting to C++ is needed. There are no strings attached to this project or catches attached, you get what you came for.

  • Windows is support right out of the box (Seen too many of these where it's just linux and remains an annoying OS gate). libsockets was programmed using a Windows 10 system to begin with. Most people use Windows to begin with. The only right thing to do was open the gate to make everybody happy.

  • Developers who want to save a bit of time and not wanting to feel guilty about asking AI for everything under the sun or digging out old stack overflow questions. Money saved, less guilt, time saved, no extra AI required, developer happy and most of all author happy because less things need vibe coding.

  • Everything plans to remain maintained. No years with no commits. This plans to at least have A couple commits within a serveral month period unless the library startes to become mature or nothing new is needed.

  • If language bindings are your thing, hope this provides you just that. Cython is a pretty popular one and it should work right out of the box.

  • If this ends your suffering, I'm glad I saved your ass, get whatever you want out of it and enjoy the rewarding results :)

What you can expect to see in the future

  • inet_ntop for IPV4 & IPV6 on all systems.
  • better support for iotcl releated functions
  • testing workflows for almost all functions in some way, shape or form.

About

An OS compatable socket library written in C with no extras

Topics

Resources

Stars

3 stars

Watchers

0 watching

Forks

Releases

Packages

Contributors

Languages