Author: Pekka Riikonen <priikone@silcnet.org>
- Copyright (C) 1997 - 2006 Pekka Riikonen
+ Copyright (C) 1997 - 2008 Pekka Riikonen
This program is free software; you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
/* If QoS was applied, return the data that was pending. */
if (sock->qos->applied && sock->qos->data_len) {
memcpy(buf, qosbuf, sock->qos->data_len);
+ len = sock->qos->data_len;
sock->qos->data_len = 0;
- return sock->qos->data_len;
+ return len;
}
/* If we have active QoS data pending, return with no data */
return -1;
}
- /* Read the data from the socket. Never read more than the max limit. */
+ /* Read the data from the socket. The qosbuf size is always the max
+ read limit size. */
len = (buf_len < sock->qos->read_limit_bytes ? buf_len :
sock->qos->read_limit_bytes);
len = read(sock->sock, qosbuf, len);
/* If we have passed the rate time limit, set our new time limit,
and zero the rate limit. This limits reads per second. */
silc_gettimeofday(&curtime);
- if (!silc_compare_timeval(&curtime, &sock->qos->next_limit)) {
+ if (silc_compare_timeval(&curtime, &sock->qos->next_limit) > 0) {
curtime.tv_sec++;
sock->qos->next_limit = curtime;
sock->qos->cur_rate = 0;
socket_stream->schedule = schedule;
if (socket_stream->notifier && socket_stream->schedule) {
+ /* Set the socket to non-blocking mode */
+ silc_net_set_socket_nonblock(socket_stream->sock);
+
/* Add the socket to scheduler. Safe to call if already added. */
if (!silc_schedule_task_add_fd(socket_stream->schedule,
socket_stream->sock,