view seobeo/seobeo.h @ 5:3e12bf044589

Fixed Dowa hashmap to recursively add files into memory.
author June Park <parkjune1995@gmail.com>
date Sat, 27 Sep 2025 16:23:04 -0700
parents 0b3b4f5887bb
children 1e61008b9980
line wrap: on
line source

#ifndef SEOBEO_SERVER_H
#define SEOBEO_SERVER_H

// --- Seobeo --- //
// Library for creating sockets, binding sockets, and listening to a sockets.
// Sending and unpacking bytes of data. 

#include <stdio.h>
#include <stdlib.h>
#include <unistd.h>
#include <errno.h>
#include <string.h>
#include <sys/types.h>
#include <sys/socket.h>
#include <netinet/in.h>
#include <netdb.h>
#include <arpa/inet.h>
#include <sys/wait.h>
#include <signal.h>
#include <fcntl.h>

#include "dowa/dowa.h"

#define INITIAL_BUFFER_CAPACITY 4096

typedef struct {
  int     socket; 
  char    *host;
  char    *port;

  uint8   *read_buffer;
  uint32  read_buffer_capacity;
  uint32  read_buffer_len; // current size
  uint32  read_buffer_pos; // TODO: Implement this for client 

  uint8   *write_buffer;
  uint32  write_buffer_capacity;
  uint32  write_buffer_len; // current size

  void    *file;
  void    *text_copy;
  char    *file_name;
} Sebeo_Handle, *Seobeo_PHandle;


// --- Socket, IP related --- //
extern int            Seobeo_CreateSocket(int32 stream, const char *host,  const char* port, int32 backlog);
extern void           *Seobeo_GetIP4OrIP6(struct sockaddr *sa);

// --- TCP --- //
extern Seobeo_PHandle Seobeo_Stream_Handle_Create(const char *host,  const char* port);
extern Seobeo_PHandle Seobeo_Stream_Handle_Accept(Seobeo_PHandle server_h);

// --- Helper functions --- //
extern void           Seobeo_Handle_Destroy(Seobeo_PHandle h);
extern int            Seobeo_Handle_Flush(Seobeo_PHandle h);
extern int            Seobeo_Handle_QueueData(Seobeo_PHandle h, const uint8_t *data, uint32_t data_size);

#endif