Skip to content

Instantly share code, notes, and snippets.

View frevib's full-sized avatar

Hielke de Vries frevib

View GitHub Profile
// create socket
int sock = socket(...);
// send bytes to the socket
send(sock, buffer, ...);
// receive bytes from the socket
recv(sock, buffer, ...);
HTTP.get("https://ing.com")
// execution continues without delay
foo()
val response = HTTP.get("https://ing.com")
// wait 30 ms
foo()
while(1) {
// check all sockets for ready data
}
// many_sockets you want to monitor
epoll_ctl(many_sockets);
while(1) {
// blocks if there are is no ready data
int events = epoll_wait(many_sockets)
// handle_events
while(true) {
// check if there is data available in the socket
}
global _start
section .text
_start: mov rax, 1 ; system call for write
mov rdi, 1 ; file handle 1 is stdout
mov rsi, message ; address of string to output
mov rdx, 13 ; number of bytes
syscall ; invoke operating system to do the write
mov rax, 60 ; system call for exit
fun requestUrl() {
// call network IO
val response = Http.get("https://ing.com")
// wait until response has returned...
processResponse(response)
// continue execution
foo()
fun requestUrl() {
// call network IO
// when data is ready call .success()
Http
.get("https://ing.com")
.success((response) -> print(response.data))
// continue execution
foo()
while(true) {
// check if one of the sockets in your "interest list" has ready data.
// This call will block if there is no ready data.
int amount_of_new_events = kqueue(events_to_check, new_events, ...)
// When there is ready data in at least one file descriptor, execution continues
// and all the events in `new_events` is checked.
for (int i = 0; i < amount_of_new_events; i++) {
Event event = new_events[i]