upsilon/software/src/sock.h

30 lines
962 B
C
Raw Normal View History

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
2023-04-02 23:14:19 -04:00
/* Read data into buffer. Returns 0 if buffer is filled. This is
2023-03-23 18:25:29 -04:00
* raw binary (no NUL termination).
*/
2023-04-02 23:14:19 -04:00
int 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
2023-04-02 23:14:19 -04:00
* does not have to be NUL terminated. Returns 0 when all data has
* been written.
2023-03-23 18:25:29 -04:00
*/
2023-04-02 23:14:19 -04:00
int sock_write_buf(int sock, struct bufptr *bp);
2023-03-23 18:25:29 -04:00
/* 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, ...);