https://github.com/marcosnicolau/redilon
Redilón is an ultralightweight, simple, fast and opinionated c library for sockets communication.
https://github.com/marcosnicolau/redilon
Last synced: 2 months ago
JSON representation
Redilón is an ultralightweight, simple, fast and opinionated c library for sockets communication.
- Host: GitHub
- URL: https://github.com/marcosnicolau/redilon
- Owner: MarcosNicolau
- License: mit
- Created: 2024-04-02T22:27:06.000Z (about 1 year ago)
- Default Branch: main
- Last Pushed: 2024-04-05T22:28:26.000Z (about 1 year ago)
- Last Synced: 2024-10-05T12:41:03.299Z (8 months ago)
- Language: C
- Size: 26.4 KB
- Stars: 0
- Watchers: 1
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: readme.md
- License: LICENSE
Awesome Lists containing this project
README
# Redilón
Redilón is an ultralightweight, simple, fast and opinionated c library for sockets communication that features:
- An intuitive api
- A standard packet serialization protocol
- Two server mechanisms: **async non-blocking io** and **on-demand**
- Robust error handling
- No memory leaks## Installation
The installation is simple, just run:
- `make`
- `sudo make install`Then you'd just include the library like so
```c
#include "redilon.h"
```If you want to uninstall the lib run `sudo make uninstall && make clean`
## Basic Usage
See [here](./examples/) for more detailed examples.
Create a server:
```c
int main()
{
int server_fd = redilon_createTcpServer(PORT, QUEUE_SIZE);
if (server_fd == -1)
{
printf("err while creating server: [%s]\n", strerror(errno));
return -1;
}
printf("Server started listening in port %s\n", PORT);int epoll_fd;
// server conf
redilon_AsyncServerConf conf;
conf.server_fd = server_fd;
conf.epoll_fd = &epoll_fd;
conf.max_clients = MAX_CLIENTS;
conf.handlersArgs = NULL;
conf.requestHandler = handleRequest;
conf.onConnectionClosed = onConnectionClosed;
conf.onNewConnection = NULL;int status = redilon_acceptConnectionsAsync(&conf);
if (status == -1)
{
printf("the server has quit unexpectedly: %s", strerror(errno));
return 1;
}// should never reach this point
return 0;
}```
Create a client:
```c
int main() {
int server_fd = redilon_connectToTcpServer(HOST, PORT);
if (server_fd == -1)
{
printf("err while connecting to server: [%s]\n", strerror(errno));
return NULL;
}
redilon_Packet *packet = redilon_createPacket(GET_RESOURCES);
// we pass the resources as an argument to the handle response
int res = redilon_sendToServer(server_fd, packet, handleResponse, resources);
}
```