Author: Pekka Riikonen <priikone@silcnet.org>
- Copyright (C) 1997 - 2006 Pekka Riikonen
+ Copyright (C) 1997 - 2007 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 (!sock->qos) {
len = read(sock->sock, buf, buf_len);
if (len < 0) {
+ silc_set_errno_posix(errno);
if (errno == EAGAIN || errno == EINTR) {
SILC_LOG_DEBUG(("Could not read immediately, will do it later"));
silc_schedule_set_listen_fd(sock->schedule, sock->sock,
+ silc_schedule_get_fd_events(sock->schedule,
+ sock->sock) |
SILC_TASK_READ, FALSE);
return -1;
}
SILC_LOG_DEBUG(("Cannot read from socket: %d:%s",
sock->sock, strerror(errno)));
silc_schedule_unset_listen_fd(sock->schedule, sock->sock);
- sock->sock_error = errno;
return -2;
}
sock->qos->read_limit_bytes);
len = read(sock->sock, qosbuf, len);
if (len < 0) {
+ silc_set_errno_posix(errno);
if (errno == EAGAIN || errno == EINTR) {
SILC_LOG_DEBUG(("Could not read immediately, will do it later"));
silc_schedule_set_listen_fd(sock->schedule, sock->sock,
+ silc_schedule_get_fd_events(sock->schedule,
+ sock->sock) |
SILC_TASK_READ, FALSE);
return -1;
}
silc_schedule_unset_listen_fd(sock->schedule, sock->sock);
silc_schedule_task_del_by_context(sock->schedule, sock->qos);
sock->qos->data_len = 0;
- sock->sock_error = errno;
return -2;
}
/* 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;
ret = write(sock->sock, data, data_len);
if (ret < 0) {
+ silc_set_errno_posix(errno);
if (errno == EAGAIN || errno == EINTR) {
SILC_LOG_DEBUG(("Could not write immediately, will do it later"));
silc_schedule_set_listen_fd(sock->schedule, sock->sock,
}
SILC_LOG_DEBUG(("Cannot write to socket: %s", strerror(errno)));
silc_schedule_unset_listen_fd(sock->schedule, sock->sock);
- sock->sock_error = errno;
return -2;
}
return silc_socket_stream_write(stream, data, data_len);
}
-#if 0
-/* Returns human readable socket error message */
-
-SilcBool silc_socket_get_error(SilcStream sock, char *error,
- SilcUInt32 error_len)
-{
- char *err;
-
- if (!sock->sock_error)
- return FALSE;
-
- err = strerror(sock->sock_error);
- if (strlen(err) > error_len)
- return FALSE;
-
- memset(error, 0, error_len);
- memcpy(error, err, strlen(err));
- return TRUE;
-}
-#endif /* 0 */
-
/* Closes socket */
SilcBool silc_socket_stream_close(SilcStream stream)
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,