Exemplo n.º 1
0
void
cserve2_client_deliver(Client *client)
{
   size_t sent, size;
   const char *str;

   if (!client->msg.pending)
     {
        Fd_Flags cur_flags;
        cserve2_fd_watch_flags_get(client->socket, &cur_flags);
        cur_flags ^= FD_WRITE;
        cserve2_fd_watch_flags_set(client->socket, cur_flags);
        return;
     }

   size = eina_binbuf_length_get(client->msg.pending);
   str = (const char *)eina_binbuf_string_get(client->msg.pending);
   sent = cserve2_client_write(client, str, size);
   if (sent == size)
     {
        eina_binbuf_free(client->msg.pending);
        client->msg.pending = NULL;
        return;
     }

   eina_binbuf_remove(client->msg.pending, 0, sent);
}
Exemplo n.º 2
0
ssize_t
cserve2_client_send(Client *client, const void *data, size_t size)
{
   ssize_t sent;

   debug_msg("sent", data, size);
   if (client->msg.pending)
     {
        eina_binbuf_append_length
           (client->msg.pending, (unsigned char *)data, size);
        return size;
     }

   sent = cserve2_client_write(client, data, size);
   if ((sent < 0) && ((errno != EAGAIN) && (errno != EWOULDBLOCK)))
     {
        // FIXME: Big error when writing on the socket to the client,
        // so we must close the connection to the client and remove
        // its references inside our cache.
        WRN("Error on socket with client %d: %s", client->id, strerror(errno));
        if (client->msg.reading)
          _client_msg_free(client);
        cserve2_client_del(client);
        return sent;
     }
   if (sent < 0)
     sent = 0;
   if (sent < (int)size)
     {
        Fd_Flags cur_flags;
        client->msg.pending = eina_binbuf_new();
        eina_binbuf_append_length
           (client->msg.pending, (unsigned char *)data + sent, size - sent);
        cserve2_fd_watch_flags_get(client->socket, &cur_flags);
        cur_flags |= FD_WRITE;
        cserve2_fd_watch_flags_set(client->socket, cur_flags);
     }
   return size;
}