void *incoming_connection(void *arg) { char readline[MAXLINE]; struct thread_argument *ta = (struct thread_argument *)arg; struct context *context = context_new(true, true); context->find = ta->find; for (;;) { bzero(readline, sizeof(readline)); int n; if (((n = CyaSSL_read(ta->ssl, readline, MAXLINE)) <= 0)) { fprintf(stderr, "client closed connection\n"); goto free_ssl; } fprintf(stderr, "%d bytes received: %s\n", n, readline); struct byte_array *raw_message = byte_array_new_size(n); raw_message->data = (uint8_t*)readline; int32_t raw_message_length = serial_decode_int(raw_message); assert_message(raw_message_length < MAXLINE, "todo: handle long messages"); struct variable *message = variable_deserialize(context, raw_message); struct variable *listener = (struct variable *)map_get(server_listeners, (void*)(VOID_INT)ta->fd); vm_call(context, listener, message); } free_ssl: CyaSSL_free(ta->ssl); // Free CYASSL object free(ta); context_del(context); return NULL; }
static inline struct variable *cfnc_deserialize(struct context *context) { struct variable *args = (struct variable*)stack_pop(context->operand_stack); struct variable *indexable = (struct variable*)array_get(args->list.ordered, 0); struct byte_array *bits = indexable->str; //byte_array_reset(bits); return variable_deserialize(context, bits); }
struct variable *sys_load(struct context *context) { struct variable *value = (struct variable*)stack_pop(context->operand_stack); struct variable *path = (struct variable*)array_get(value->list.ordered, 1); struct byte_array *file_bytes = read_file(path->str, 0, 0); if (NULL == file_bytes) return variable_new_nil(context); struct variable *v = variable_deserialize(context, file_bytes); byte_array_del(file_bytes); return v; }