Fix packet sending
This commit is contained in:
parent
272afa1999
commit
d810a9cca1
@ -115,14 +115,17 @@ static uint32_t write_server(fs_node_t * node, uint32_t offset, uint32_t size, u
|
||||
if (head->target == NULL) {
|
||||
/* Brodcast packet */
|
||||
foreach(f, p->clients) {
|
||||
send_to_client(p, (pex_client_t *)f->value, size - sizeof(header_t), &head->data);
|
||||
debug_print(NOTICE, "Sending to client 0x%x", f->value);
|
||||
send_to_client(p, (pex_client_t *)f->value, size - sizeof(header_t), head->data);
|
||||
}
|
||||
debug_print(NOTICE, "Done broadcasting to clients.\n");
|
||||
return size;
|
||||
} else if (head->target->parent != p) {
|
||||
debug_print(ERROR, "[pex] Invalid packet from server?");
|
||||
return -1;
|
||||
}
|
||||
|
||||
send_to_client(p, head->target, size - sizeof(header_t), &head->data);
|
||||
send_to_client(p, head->target, size - sizeof(header_t), head->data);
|
||||
|
||||
return size;
|
||||
}
|
||||
@ -138,12 +141,15 @@ static uint32_t read_client(fs_node_t * node, uint32_t offset, uint32_t size, ui
|
||||
receive_packet(c->pipe, &packet);
|
||||
|
||||
if (packet->size > size) {
|
||||
debug_print(ERROR, "[pex] Client is not reading enough bytes to hold packet of size %d", packet->size);
|
||||
return -1;
|
||||
}
|
||||
|
||||
memcpy(buffer, &packet->data, packet->size);
|
||||
uint32_t out = packet->size;
|
||||
|
||||
debug_print(NOTICE, "[pex] Client received packet of size %d", packet->size);
|
||||
|
||||
free(packet);
|
||||
return out;
|
||||
}
|
||||
@ -185,6 +191,8 @@ static void open_pex(fs_node_t * node, unsigned int flags) {
|
||||
node->read = read_client;
|
||||
node->write = write_client;
|
||||
|
||||
list_insert(t->clients, client);
|
||||
|
||||
/* XXX: Send plumbing message to server for new client connection */
|
||||
debug_print(NOTICE, "[pex] Client connected: %s:0%x", t->name, node->inode);
|
||||
} else if (flags & O_CREAT && !t->fresh) {
|
||||
|
@ -30,13 +30,31 @@ int main(int argc, char * argv[]) {
|
||||
|
||||
fprintf(client, "Hello World!");
|
||||
|
||||
packet_t * p = malloc(PACKET_SIZE);
|
||||
memset(p, 0x00, PACKET_SIZE);
|
||||
fprintf(stdout, "Reading %d...\n", PACKET_SIZE);
|
||||
size_t size = read(fileno(server), p, PACKET_SIZE);
|
||||
{
|
||||
packet_t * p = malloc(PACKET_SIZE);
|
||||
memset(p, 0x00, PACKET_SIZE);
|
||||
fprintf(stdout, "Reading %d...\n", PACKET_SIZE);
|
||||
size_t size = read(fileno(server), p, PACKET_SIZE);
|
||||
|
||||
fprintf(stdout, "Received a packet of size %d (%d) from client [0x%x]\n", p->size, size, p->source);
|
||||
fprintf(stdout, "Packet contents: %s\n", p->data);
|
||||
fprintf(stdout, "Received a packet of size %d (%d) from client [0x%x]\n", p->size, size, p->source);
|
||||
fprintf(stdout, "Packet contents: %s\n", p->data);
|
||||
free(p);
|
||||
}
|
||||
|
||||
{
|
||||
header_t * broadcast = malloc(sizeof(header_t) + MAX_PACKET_SIZE);
|
||||
|
||||
broadcast->target = 0;
|
||||
size_t size = sprintf(broadcast->data, "Hello everyone!\n") + 1;
|
||||
|
||||
fwrite(broadcast, 1, sizeof(header_t) + size, server);
|
||||
free(broadcast);
|
||||
}
|
||||
|
||||
char out[MAX_PACKET_SIZE];
|
||||
memset(out, 0, MAX_PACKET_SIZE);
|
||||
size_t size = read(fileno(client), out, MAX_PACKET_SIZE);
|
||||
fprintf(stdout, "Response received from server (size=%d) %s\n", size, out);
|
||||
|
||||
|
||||
fclose(client);
|
||||
|
Loading…
Reference in New Issue
Block a user