mirror of
https://github.com/kanjitalk755/macemu.git
synced 2024-09-30 13:56:16 +00:00
Implement rpc_wait_dispatch()
This commit is contained in:
parent
3fda1a3af7
commit
758050ac73
@ -43,6 +43,7 @@ extern int rpc_exit(rpc_connection_t *connection);
|
|||||||
extern int rpc_listen_socket(rpc_connection_t *connection);
|
extern int rpc_listen_socket(rpc_connection_t *connection);
|
||||||
extern int rpc_listen(rpc_connection_t *connection);
|
extern int rpc_listen(rpc_connection_t *connection);
|
||||||
extern int rpc_dispatch(rpc_connection_t *connection);
|
extern int rpc_dispatch(rpc_connection_t *connection);
|
||||||
|
extern int rpc_wait_dispatch(rpc_connection_t *connection, int timeout);
|
||||||
extern int rpc_connection_busy(rpc_connection_t *connection);
|
extern int rpc_connection_busy(rpc_connection_t *connection);
|
||||||
|
|
||||||
// Message Passing
|
// Message Passing
|
||||||
|
@ -279,7 +279,30 @@ int rpc_exit(rpc_connection_t *connection)
|
|||||||
return RPC_ERROR_NO_ERROR;
|
return RPC_ERROR_NO_ERROR;
|
||||||
}
|
}
|
||||||
|
|
||||||
// Wait for messages to arrive on the connection port
|
// Wait for a message to arrive on the connection port
|
||||||
|
static inline int _rpc_wait_dispatch(rpc_connection_t *connection, int timeout)
|
||||||
|
{
|
||||||
|
struct timeval tv;
|
||||||
|
tv.tv_sec = timeout / 1000000;
|
||||||
|
tv.tv_usec = timeout % 1000000;
|
||||||
|
|
||||||
|
fd_set rfds;
|
||||||
|
FD_ZERO(&rfds);
|
||||||
|
FD_SET(connection->socket, &rfds);
|
||||||
|
return select(connection->socket + 1, &rfds, NULL, NULL, &tv);
|
||||||
|
}
|
||||||
|
|
||||||
|
int rpc_wait_dispatch(rpc_connection_t *connection, int timeout)
|
||||||
|
{
|
||||||
|
if (connection == NULL)
|
||||||
|
return RPC_ERROR_CONNECTION_NULL;
|
||||||
|
if (connection->type != RPC_CONNECTION_SERVER)
|
||||||
|
return RPC_ERROR_CONNECTION_TYPE_MISMATCH;
|
||||||
|
|
||||||
|
return _rpc_wait_dispatch(connection, timeout);
|
||||||
|
}
|
||||||
|
|
||||||
|
// Process incoming messages in the background
|
||||||
static void *rpc_server_func(void *arg)
|
static void *rpc_server_func(void *arg)
|
||||||
{
|
{
|
||||||
rpc_connection_t *connection = (rpc_connection_t *)arg;
|
rpc_connection_t *connection = (rpc_connection_t *)arg;
|
||||||
@ -294,13 +317,7 @@ static void *rpc_server_func(void *arg)
|
|||||||
pthread_testcancel();
|
pthread_testcancel();
|
||||||
|
|
||||||
// wait for data to arrive
|
// wait for data to arrive
|
||||||
fd_set rfds;
|
int ret = _rpc_wait_dispatch(connection, 50000);
|
||||||
FD_ZERO(&rfds);
|
|
||||||
FD_SET(connection->socket, &rfds);
|
|
||||||
struct timeval tv;
|
|
||||||
tv.tv_sec = 0;
|
|
||||||
tv.tv_usec = 50000;
|
|
||||||
int ret = select(connection->socket + 1, &rfds, NULL, NULL, &tv);
|
|
||||||
if (ret == 0)
|
if (ret == 0)
|
||||||
continue;
|
continue;
|
||||||
if (ret < 0)
|
if (ret < 0)
|
||||||
|
Loading…
Reference in New Issue
Block a user