static int string_writer_process(struct sol_flow_node *node, void *data, uint16_t port, uint16_t conn_id, const struct sol_flow_packet *packet) { struct unix_socket_data *mdata = data; const char *val; size_t len; int r; r = sol_flow_packet_get_string(packet, &val); SOL_INT_CHECK(r, < 0, r); len = strlen(val); if (unix_socket_write(mdata->un_socket, &len, sizeof(len)) < 0) { SOL_WRN("Failed to write the string length"); return -1; } return unix_socket_write(mdata->un_socket, val, len); }
static int float_writer_process(struct sol_flow_node *node, void *data, uint16_t port, uint16_t conn_id, const struct sol_flow_packet *packet) { struct unix_socket_data *mdata = data; int r; double val; r = sol_flow_packet_get_drange_value(packet, &val); SOL_INT_CHECK(r, < 0, r); return unix_socket_write(mdata->un_socket, &val, sizeof(val)); }
static int direction_vector_writer_process(struct sol_flow_node *node, void *data, uint16_t port, uint16_t conn_id, const struct sol_flow_packet *packet) { struct unix_socket_data *mdata = data; struct sol_direction_vector direction_vector; int r; r = sol_flow_packet_get_direction_vector(packet, &direction_vector); SOL_INT_CHECK(r, < 0, r); return unix_socket_write(mdata->un_socket, &direction_vector, sizeof(direction_vector)); }
static int rgb_writer_process(struct sol_flow_node *node, void *data, uint16_t port, uint16_t conn_id, const struct sol_flow_packet *packet) { struct unix_socket_data *mdata = data; struct sol_rgb rgb; int r; r = sol_flow_packet_get_rgb(packet, &rgb); SOL_INT_CHECK(r, < 0, r); return unix_socket_write(mdata->un_socket, &rgb, sizeof(rgb)); }
/* * 1 All data succesfully sent * 0 Partial send (no error) * -1 End of connection * -2 Unhandled error */ int unix_socket_client_io_write(struct unix_socket_client *client) { ssize_t sent; size_t to_send; int res; res = 0; to_send = dynar_size(&client->send_buffer) - client->msg_already_sent_bytes; if (to_send > UNIX_SOCKET_CLIENT_BUFFER) { to_send = UNIX_SOCKET_CLIENT_BUFFER; } sent = unix_socket_write(client->socket, dynar_data(&client->send_buffer) + client->msg_already_sent_bytes, to_send); if (sent > 0) { client->msg_already_sent_bytes += sent; if (client->msg_already_sent_bytes == dynar_size(&client->send_buffer)) { return (1); } } if (sent == 0) { res = -1; } if (sent < 0 && errno != EAGAIN && errno != EWOULDBLOCK && errno != EINTR) { res = -2; } return (res); }