Esempio n. 1
0
int client_connected (client_t *c)
{
    if (c->sock == MAX_SOCK_NUM)
        return 0;

    unsigned s = client_status (c);
    return ! (s == SnSR_LISTEN || s == SnSR_CLOSED || s == SnSR_FIN_WAIT ||
        (s == SnSR_CLOSE_WAIT && ! client_available (c)));
}
Esempio n. 2
0
int client_peek (client_t *c)
{
    uint8_t b;

    // Unlike recv, peek doesn't check to see if there's any data available, so we must
    if (! client_available (c))
      return -1;

    b = socket_peek (c->sock);
    return b;
}
Esempio n. 3
0
int server_available (client_t *client)
{
    unsigned sock;

    server_accept();

    for (sock = 0; sock < MAX_SOCK_NUM; sock++) {
        client_init_sock (client, sock);

        if (_socket_port[sock] == _server_port &&
              (client_status (client) == SnSR_ESTABLISHED ||
               client_status (client) == SnSR_CLOSE_WAIT)) {
            if (client_available (client)) {
                // XXX: don't always pick the lowest numbered socket.
                return 1;
            }
        }
    }
    return 0;
}
Esempio n. 4
0
void server_accept()
{
    unsigned sock;
    client_t client;
    int listening = 0;

    for (sock = 0; sock < MAX_SOCK_NUM; sock++) {
        client_init_sock (&client, sock);

        if (_socket_port[sock] == _server_port) {
            if (client_status (&client) == SnSR_LISTEN) {
                listening = 1;
            }
            else if (client_status (&client) == SnSR_CLOSE_WAIT &&
                     ! client_available (&client)) {
                client_stop (&client);
            }
        }
    }

    if (! listening) {
        server_init (_server_port);
    }
}
Esempio n. 5
0
void client_flush (client_t *c)
{
    while (client_available (c))
        client_getc (c);
}