Skip to content

Instantly share code, notes, and snippets.

@yokodake
yokodake / client.c
Created January 25, 2019 10:11
libev helloworld
#include <stdio.h>
#include <stdlib.h>
#include <netinet/in.h>
#include <string.h>
#define PORT_NO 4545
#define BUFFER_SIZE 1024
int main(int argc, char *argv[]) {
int sd;
@djarek
djarek / send_fd.cpp
Created December 6, 2018 01:59
send_fd.cpp
#include <boost/asio/coroutine.hpp>
#include <boost/asio/local/connect_pair.hpp>
#include <boost/asio/local/stream_protocol.hpp>
#include <iostream>
#include <sys/wait.h>
std::size_t
send_fd(boost::asio::local::stream_protocol::socket& socket,
int fd,
boost::system::error_code& ec)
@faberyx
faberyx / c++ daemon
Last active December 21, 2021 19:59
#include <stdio.h>
#include <signal.h>
#include <syslog.h>
#include <errno.h>
#include <stdlib.h>
#include <fcntl.h>
#include <unistd.h>
#include <string.h>
#include <sys/types.h>
#include <sys/stat.h>
@kokjo
kokjo / recvfd.c
Last active November 17, 2024 18:10
Receive a file descriptor over a abstract unix domain socket.
// compile with gcc -static -o recvfd recvfd.c
#include <sys/types.h>
#include <sys/socket.h>
#include <sys/un.h>
#include <strings.h>
static int recv_fd(int sock){
// This function does the arcane magic recving
// file descriptors over unix domain sockets
struct msghdr msg;
@kokjo
kokjo / sendfd.c
Last active April 16, 2024 10:27
Send a file descriptor over an abstract unix domain socket
// compile with: gcc -static -o sendfd sendfd.c
#include <sys/types.h>
#include <sys/socket.h>
#include <sys/un.h>
#include <strings.h>
int send_fd(int sock, int fd){
// This function does the arcane magic for sending
// file descriptors over unix domain sockets
struct msghdr msg;
@mengqingzhong
mengqingzhong / libevtest.c
Last active September 30, 2022 13:58
libev demo
#include <ev.h>
#include <unistd.h>
#include <stdio.h> // for puts
// every watcher type has its own typedef'd struct
// with the name ev_TYPE
ev_io stdin_watcher;
ev_timer timeout_watcher;
// all watcher callbacks have a similar signature
/*
* echo-server.cpp
* echo server with libev
*
* g++ -std=c++11 -Wall -Wextra -pedantic -lev timer.cpp
*
* telnet localhost 40713
*
* written by janus_wel<[email protected]>
*
@DamonHao
DamonHao / official_exapmle.c
Last active November 27, 2023 12:35
libev example
/*
* test_libv.c
*
* Created on: May 30, 2014
* Author: damonhao
*/
// a single header file is required
#include <ev.h>
#include <stdio.h> // for puts
@wangrenjun
wangrenjun / libev-client.c
Last active October 17, 2019 04:51
another libev example
/*
* Licensed under the Apache License, Version 2.0.
*
* simple libev client example
* based on multi-process and ring buffer
* [email protected]
*/
/*
gcc ./libev-client.c -c -o ./libev-client.o -I/usr/local/include/
@clemensg
clemensg / curl_libuv_example.c
Last active November 21, 2024 09:50
An example on how to use libuv with libcurl's multi interface Should be equally fast on Unixes (uses epoll/kqueue/etc like libev/libevent) but MUCH faster on Windows due to libuv's usage of IO completion ports. Could come in handy if you have to manage several hundreds or thousands of connections!
#include <stdio.h>
#include <stdlib.h>
#include <uv.h>
#include <curl/curl.h>
uv_loop_t *loop;
CURLM *curl_handle;
uv_timer_t timeout;
typedef struct curl_context_s {