return 0;
}
+static void fr_bio_fd_set_open(fr_bio_fd_t *my)
+{
+ my->info.state = FR_BIO_FD_STATE_OPEN;
+ my->info.eof = false;
+ my->info.read_blocked = false;
+ my->info.write_blocked = false;
+
+ /*
+ * Tell the caller that the socket is ready for application data.
+ */
+ if (my->cb.activate) my->cb.activate(&my->bio);
+}
+
/** Try to connect().
*
retry:
if (connect(my->info.socket.fd, (struct sockaddr *) &sockaddr, salen) == 0) {
- my->info.state = FR_BIO_FD_STATE_OPEN;
+ fr_bio_fd_set_open(my);
/*
* The source IP may have changed, so get the new one.
return fr_bio_error(IO);
}
+
/** Files are a special case of connected sockets.
*
*/
static int fr_bio_fd_init_file(fr_bio_fd_t *my)
{
- my->info.state = FR_BIO_FD_STATE_OPEN;
- my->info.eof = false;
- my->info.read_blocked = false;
- my->info.write_blocked = false;
+ fr_bio_fd_set_open(my);
/*
* Other flags may be O_CREAT, etc.
return -1;
}
- my->info.state = FR_BIO_FD_STATE_OPEN;
- my->info.eof = false;
- my->info.read_blocked = false;
- my->info.write_blocked = false;
-
- /*
- * Tell the caller that the socket is ready for application data.
- */
- if (my->cb.activate) my->cb.activate(&my->bio);
+ fr_bio_fd_set_open(my);
return 0;
}
int fr_bio_fd_init_accept(fr_bio_fd_t *my)
{
- my->info.state = FR_BIO_FD_STATE_OPEN;
- my->info.eof = false;
- my->info.read_blocked = true;
- my->info.write_blocked = false; /* don't select() for write */
-
my->bio.read = fr_bio_fd_read_accept;
my->bio.write = fr_bio_null_write;
return -1;
}
+ fr_bio_fd_set_open(my);
+
return 0;
}
if (my->info.state == FR_BIO_FD_STATE_OPEN) return 0;
+ /*
+ * The caller may just call us without caring about the underlying bio.
+ */
+ if ((my->info.socket.af == AF_FILE_BIO) || (my->info.type == FR_BIO_FD_ACCEPT)) {
+ fr_bio_fd_set_open(my);
+ return 0;
+ }
+
if (my->info.state != FR_BIO_FD_STATE_CONNECTING) return fr_bio_error(GENERIC);
/*