struct utcp *b;
struct utcp_connection *c;
-int do_recv(struct utcp_connection *x, void *data, size_t len) {
+int do_recv(struct utcp_connection *x, const void *data, size_t len) {
if(!len) {
if(errno)
fprintf(stderr, "%p Error: %s\n", x->utcp, strerror(errno));
utcp_accept(c, do_recv, NULL);
}
-int do_send(struct utcp *utcp, void *data, size_t len) {
+int do_send(struct utcp *utcp, const void *data, size_t len) {
static int count = 0;
if(++count > 1000) {
fprintf(stderr, "Too many packets!\n");
int dir = 3;
bool running = true;
-int do_recv(struct utcp_connection *c, void *data, size_t len) {
+int do_recv(struct utcp_connection *c, const void *data, size_t len) {
if(!data || !len) {
if(errno)
fprintf(stderr, "Error: %s\n", strerror(errno));
c = nc;
}
-int do_send(struct utcp *utcp, void *data, size_t len) {
+int do_send(struct utcp *utcp, const void *data, size_t len) {
int s = *(int *)utcp->priv;
return send(s, data, len, MSG_DONTWAIT);
}
fprintf(stderr, "%p new state: %s\n", c->utcp, strstate[state]);
}
-static void print_packet(void *pkt, size_t len) {
+static void print_packet(const void *pkt, size_t len) {
struct hdr hdr;
if(len < sizeof hdr) {
fprintf(stderr, "short packet (%zu bytes)\n", len);
if(len > sizeof hdr) {
fprintf(stderr, " data=");
for(int i = sizeof hdr; i < len; i++) {
- char *data = pkt;
+ const char *data = pkt;
fprintf(stderr, "%c", data[i] >= 32 ? data[i] : '.');
}
}
set_state(c, ESTABLISHED);
}
-ssize_t utcp_send(struct utcp_connection *c, void *data, size_t len) {
+ssize_t utcp_send(struct utcp_connection *c, const void *data, size_t len) {
if(c->reapable) {
fprintf(stderr, "Error: send() called on closed connection %p\n", c);
errno = EBADF;
return a -b;
}
-int utcp_recv(struct utcp *utcp, void *data, size_t len) {
+int utcp_recv(struct utcp *utcp, const void *data, size_t len) {
if(!utcp) {
errno = EFAULT;
return -1;
typedef bool (*utcp_pre_accept_t)(struct utcp *utcp, uint16_t port);
typedef void (*utcp_accept_t)(struct utcp_connection *utcp_connection, uint16_t port);
-typedef int (*utcp_send_t)(struct utcp *utcp, void *data, size_t len);
-typedef int (*utcp_recv_t)(struct utcp_connection *connection, void *data, size_t len);
+typedef int (*utcp_send_t)(struct utcp *utcp, const void *data, size_t len);
+typedef int (*utcp_recv_t)(struct utcp_connection *connection, const void *data, size_t len);
extern struct utcp *utcp_init(utcp_accept_t accept, utcp_pre_accept_t pre_accept, utcp_send_t send, void *priv);
extern void utcp_exit(struct utcp *utcp);
extern struct utcp_connection *utcp_connect(struct utcp *utcp, uint16_t port, utcp_recv_t recv, void *priv);
extern void utcp_accept(struct utcp_connection *utcp, utcp_recv_t recv, void *priv);
-extern ssize_t utcp_send(struct utcp_connection *connection, void *data, size_t len);
-extern int utcp_recv(struct utcp *utcp, void *data, size_t len);
+extern ssize_t utcp_send(struct utcp_connection *connection, const void *data, size_t len);
+extern int utcp_recv(struct utcp *utcp, const void *data, size_t len);
extern int utcp_close(struct utcp_connection *connection);
extern int utcp_abort(struct utcp_connection *connection);
extern int utcp_shutdown(struct utcp_connection *connection, int how);