getting closer with the distribution infrastructure

git-svn-id: svn://anubis/fart/trunk@230 7f9b0f55-74a9-4bce-be96-3c2cd072584d
This commit is contained in:
Josh Holtrop 2009-04-07 11:02:39 +00:00
parent c9c3c942fb
commit af4e4d571e

View File

@ -115,6 +115,7 @@ void connection_thread(distrib::connection_thread_arg_t * arg)
int client_socket = arg->client_socket;
delete arg;
bool done = false;
/* loop listening for messages from the client */
for (;;)
{
@ -122,7 +123,30 @@ void connection_thread(distrib::connection_thread_arg_t * arg)
int nread = read(client_socket, &msg_type, sizeof(msg_type));
if (nread < 0)
break;
cout << "Read message type " << msg_type << "!" << endl;
switch (msg_type)
{
case MSG_WANT_DATA:
{
int task = the_distrib->getTask();
if (write(client_socket, &task, sizeof(task)) < 0)
done = true;
}
break;
case MSG_SEND_DATA:
{
unsigned char data[3 * UNIT_TASK_SIZE];
int task;
if (read(client_socket, &task, sizeof(task)) < 0)
done = true;
else if (read(client_socket, &data[0], sizeof(data)) < 0)
done = true;
else
the_distrib->send_data(task, &data[0], sizeof(data));
}
break;
default:
break;
}
}
close(client_socket);
}
@ -269,6 +293,7 @@ int distrib::send_data(int task, unsigned char * data, int num_bytes)
{
int msg_header = MSG_SEND_DATA; /* send data */
if ( write(m_client_socket, &msg_header, sizeof(msg_header)) < 0
|| write(m_client_socket, &task, sizeof(task)) < 0
|| write(m_client_socket, data, num_bytes) < 0)
{
return -1;