minimal_server improved
static neat_error_code
on_readable(struct neat_flow_operations *opCB)
{
+ uint32_t bytes_read = 0;
+ unsigned char buffer[32];
+
+ if (neat_read(opCB->ctx, opCB->flow, buffer, 31, &bytes_read, NULL, 0) == NEAT_OK) {
+ buffer[bytes_read] = 0;
+ fprintf(stdout, "Read %u bytes:\n%s", bytes_read, buffer);
+ }
+
return NEAT_OK;
}
static neat_error_code
-on_writable(struct neat_flow_operations *ops)
+on_writable(struct neat_flow_operations *opCB)
{
const unsigned char message[] = "Hello, this is NEAT!";
- neat_write(ops->ctx, ops->flow, message, 20, NULL, 0);
+ neat_write(opCB->ctx, opCB->flow, message, 20, NULL, 0);
return NEAT_OK;
}
static neat_error_code
-on_all_written(struct neat_flow_operations *ops)
+on_all_written(struct neat_flow_operations *opCB)
{
- neat_close(ops->ctx, ops->flow);
+ neat_close(opCB->ctx, opCB->flow);
return NEAT_OK;
}
static neat_error_code
-on_connected(struct neat_flow_operations *ops)
+on_connected(struct neat_flow_operations *opCB)
{
- ops->on_writable = on_writable;
- ops->on_all_written = on_all_written;
- neat_set_operations(ops->ctx, ops->flow, ops);
+ opCB->on_writable = on_writable;
+ opCB->on_all_written = on_all_written;
+ neat_set_operations(opCB->ctx, opCB->flow, opCB);
return NEAT_OK;
}
@@ -52,7 +60,7 @@ main(int argc, char *argv[])
flow = neat_new_flow(ctx);
memset(&ops, 0, sizeof(ops));
- // ops.on_readable = on_readable;
+ ops.on_readable = on_readable;
ops.on_connected = on_connected;
neat_set_operations(ctx, flow, &ops);
