Files @ 85419b0950c7
Branch filter:

Location: CSY/reowolf/examples/interop_2_pseudo_socket/main.c - annotation

MH
Rewrote typing to use indices.

Currently it is slower than before, because we do a HashMap lookup
followed up by actually using the index. But it serves as the basis
for a faster type inferencer.

The main goal, however, is to fix the manner in which polymorph
types are determined. The typing queue of functions still needs to
correctly write this data to the type table.
/* This example demonstrates:
- Reowolf's pseudo-socket API mimics the API of UDP sockets
- This example corresponds closely with that of the socket API, differing only in:
    1. an added import of the pseudo-socket header file
    2. (pseudo-)socket operations' identifiers are prefixed with `rw_` (short for "Reowolf"). 
*/
#include <netinet/in.h> // definies socketaddr_in
#include <stdio.h>  // defines printf
#include <stdlib.h> // defines malloc, free
#include <unistd.h> // defines close
#include <arpa/inet.h> // defines inet_addr
#include "../../pseudo_socket.h"
#define BUFSIZE 512
int main() {
    // --- setup ---
    struct sockaddr_in addrs[2]; 
    addrs[0].sin_family = AF_INET;
    addrs[0].sin_port = htons(8000);
    inet_pton(AF_INET, "127.0.0.1", &addrs[0].sin_addr.s_addr);
    addrs[1].sin_family = AF_INET;
    addrs[1].sin_port = htons(8001);
    inet_pton(AF_INET, "127.0.0.1", &addrs[1].sin_addr.s_addr);
    int fd = rw_socket(AF_INET, SOCK_DGRAM, 0); 
    rw_bind(fd, (const struct sockaddr *)&addrs[0], sizeof(addrs[0]));
    rw_connect(fd, (const struct sockaddr *)&addrs[1], sizeof(addrs[1]));
    // --- communication ---
    char * buffer = malloc(BUFSIZE);
    size_t msglen, i;
    msglen = rw_recv(fd, (void *)buffer, BUFSIZE, 0);
    for(i=0; i<msglen; i++) {
        printf("%02X", buffer[i]);
    }
    // --- cleanup ---
    rw_close(fd);
    free(buffer);
    return 0;
}