2022-09-16 18:01:34 -04:00
|
|
|
#pragma once
|
2023-03-23 18:25:29 -04:00
|
|
|
#include <stdarg.h>
|
|
|
|
#include "buf.h"
|
2023-03-03 03:06:50 -05:00
|
|
|
|
2023-03-23 18:25:29 -04:00
|
|
|
/* Initialize server to listen on the port passed as an argument.
|
|
|
|
*/
|
2022-09-16 18:01:34 -04:00
|
|
|
int server_init_sock(int port);
|
2023-03-03 03:06:50 -05:00
|
|
|
|
2023-03-23 18:25:29 -04:00
|
|
|
/* Accept a client and allocate a file descriptor for the client.
|
|
|
|
*/
|
2022-09-16 18:01:34 -04:00
|
|
|
int server_accept_client(int server);
|
2023-03-23 18:25:29 -04:00
|
|
|
|
|
|
|
/* Read data into buffer. Returns false if error occurs. This is
|
|
|
|
* raw binary (no NUL termination).
|
|
|
|
*/
|
2023-04-02 17:46:10 -04:00
|
|
|
bool sock_read_buf(int sock, struct bufptr *bp, bool entire);
|
2023-03-23 18:25:29 -04:00
|
|
|
|
|
|
|
/* Write raw buffer data into socket. This data is raw binary and
|
|
|
|
* does not have to be NUL terminated.
|
|
|
|
*/
|
|
|
|
bool sock_write_buf(int sock, struct bufptr *bp);
|
|
|
|
|
|
|
|
/* Write formatted string into socket. The user must provide a
|
|
|
|
* buffer into which the formatted string is written. These return
|
|
|
|
* with a buf.h error, or BUF_OK when successful.
|
|
|
|
*/
|
|
|
|
int sock_vprintf(int sock, struct bufptr *bp, const char *fmt, va_list va);
|
|
|
|
int sock_printf(int sock, struct bufptr *bp, const char *fmt, ...);
|