}
/* Generate keys */
- silc_pkcs_alloc(alg, &pkcs);
+ silc_pkcs_alloc(alg, SILC_PKCS_SILC, &pkcs);
silc_pkcs_generate_key(pkcs, key_len_bits, rng);
/* Save public key into file */
}
if (return_pkcs) {
- silc_pkcs_alloc((*return_public_key)->name, return_pkcs);
+ silc_pkcs_alloc((*return_public_key)->name, SILC_PKCS_SILC, return_pkcs);
silc_pkcs_public_key_set(*return_pkcs, *return_public_key);
silc_pkcs_private_key_set(*return_pkcs, *return_private_key);
}
fingerprint = silc_hash_fingerprint(NULL, pk, pk_len);
babbleprint = silc_hash_babbleprint(NULL, pk, pk_len);
- if (silc_pkcs_alloc(public_key->name, &pkcs)) {
+ if (silc_pkcs_alloc(public_key->name, SILC_PKCS_SILC, &pkcs)) {
key_len = silc_pkcs_public_key_set(pkcs, public_key);
silc_pkcs_free(pkcs);
}
{
SilcFDStream stream;
- if (read_fd < 1 && write_fd < 1)
+ if (read_fd < 1)
return NULL;
stream = silc_calloc(1, sizeof(*stream));
stream->ops = &silc_fd_stream_ops;
stream->schedule = schedule;
stream->fd1 = read_fd;
- stream->fd1 = write_fd;
+ stream->fd2 = write_fd;
/* Schedule the file descriptors */
if (write_fd > 0) {
silc_schedule_task_add_fd(schedule, write_fd, silc_fd_stream_io, stream);
- silc_net_set_socket_nonblock(write_fd);
+ silc_file_set_nonblock(write_fd);
}
if (read_fd > 0) {
silc_schedule_task_add_fd(schedule, read_fd, silc_fd_stream_io, stream);
silc_schedule_set_listen_fd(schedule, read_fd, SILC_TASK_READ, FALSE);
- silc_net_set_socket_nonblock(read_fd);
+ silc_file_set_nonblock(read_fd);
if (write_fd < 1)
- write_fd = read_fd;
+ stream->fd2 = stream->fd1;
}
return stream;
if (!SILC_IS_FD_STREAM(fd_stream))
return FALSE;
- if (fd_stream->fd1 > 0)
+ if (fd_stream->fd1 > 0) {
silc_file_close(fd_stream->fd1);
- if (fd_stream->fd2 > 0 && fd_stream->fd2 != fd_stream->fd1)
+ silc_schedule_unset_listen_fd(fd_stream->schedule, fd_stream->fd1);
+ }
+ if (fd_stream->fd2 > 0 && fd_stream->fd2 != fd_stream->fd1) {
silc_file_close(fd_stream->fd2);
+ silc_schedule_unset_listen_fd(fd_stream->schedule, fd_stream->fd2);
+ }
return TRUE;
}
return;
silc_fd_stream_close(stream);
+ silc_schedule_task_del_by_fd(fd_stream->schedule, fd_stream->fd1);
+ silc_schedule_task_del_by_fd(fd_stream->schedule, fd_stream->fd2);
silc_free(stream);
}
* interface should be used only with real file descriptors, not with
* sockets. Use the SILC Socket Stream for sockets.
*
+ * SILC File Descriptor Stream is not thread-safe. If same stream must be
+ * used in multithreaded environment concurrency control must be employed.
+ *
***/
#ifndef SILCFDSTREAM_H
***/
int silc_file_close(int fd);
+/****f* silcutil/SilcNetAPI/silc_file_set_nonblock
+ *
+ * SYNOPSIS
+ *
+ * int silc_file_set_nonblock(int fd);
+ *
+ * DESCRIPTION
+ *
+ * Sets the file descriptor to non-blocking mode.
+ *
+ ***/
+int silc_file_set_nonblock(int fd);
+
/****f* silcutil/SilcFileUtilAPI/silc_file_readfile
*
* SYNOPSIS
* Stream provides also Quality of Service (QoS) support that can be used
* to control the throughput of the stream.
*
+ * SILC Socket Stream is not thread-safe. If the same socket stream must be
+ * used in multithreaded environment concurrency control must be employed.
+ *
***/
#ifndef SILCSOCKETSTREAM_H
* other stream API derived from this API can use this same interface for
* sending and receiving.
*
+ * Note that stream implementations usually are not thread-safe. Always
+ * verify whether a stream implementation is thread-safe by checking their
+ * corresponding documentation.
+ *
***/
#ifndef SILCSTREAM_H
{
return gettimeofday(p, NULL);
}
+
+int silc_file_set_nonblock(int fd)
+{
+ return fcntl(fd, F_SETFL, fcntl(fd, F_GETFL, 0) | O_NONBLOCK);
+}
+
{
return silc_get_username();
}
+
+int silc_file_set_nonblock(int fd)
+{
+ return fcntl(fd, F_SETFL, fcntl(fd, F_GETFL, 0) | O_NONBLOCK);
+}