summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--socket.c42
-rw-r--r--stream.h1
2 files changed, 21 insertions, 22 deletions
diff --git a/socket.c b/socket.c
index ea9b9b74..512b464c 100644
--- a/socket.c
+++ b/socket.c
@@ -734,6 +734,27 @@ static int to_connect(int fd, struct sockaddr *addr, socklen_t len,
}
}
+static val open_sockfd(val fd, val family, val type, val mode_str)
+{
+ struct stdio_mode m, m_rpb = stdio_mode_init_rpb;
+
+ if (type == num_fast(SOCK_DGRAM)) {
+ return make_dgram_sock_stream(c_num(fd), family, nil, 0, 0, 0, 0,
+ parse_mode(mode_str, m_rpb), 0);
+ } else {
+ FILE *f = (errno = 0, w_fdopen(c_num(fd), c_str(normalize_mode(&m, mode_str, m_rpb))));
+
+ if (!f) {
+ close(c_num(fd));
+ uw_throwf(file_error_s, lit("error creating stream for socket ~a: ~d/~s"),
+ fd, num(errno), string_utf8(strerror(errno)), nao);
+ }
+
+ return set_mode_props(m, make_sock_stream(f, family, type));
+ }
+}
+
+
static val sock_connect(val sock, val sockaddr, val timeout)
{
val sfd = stream_fd(sock);
@@ -977,27 +998,6 @@ static val sock_recv_timeout(val sock, val usec)
}
#endif
-
-val open_sockfd(val fd, val family, val type, val mode_str)
-{
- struct stdio_mode m, m_rpb = stdio_mode_init_rpb;
-
- if (type == num_fast(SOCK_DGRAM)) {
- return make_dgram_sock_stream(c_num(fd), family, nil, 0, 0, 0, 0,
- parse_mode(mode_str, m_rpb), 0);
- } else {
- FILE *f = (errno = 0, w_fdopen(c_num(fd), c_str(normalize_mode(&m, mode_str, m_rpb))));
-
- if (!f) {
- close(c_num(fd));
- uw_throwf(file_error_s, lit("error creating stream for socket ~a: ~d/~s"),
- fd, num(errno), string_utf8(strerror(errno)), nao);
- }
-
- return set_mode_props(m, make_sock_stream(f, family, type));
- }
-}
-
val open_socket(val family, val type, val mode_str)
{
int fd = socket(c_num(family), c_num(type), 0);
diff --git a/stream.h b/stream.h
index 2ce7a5ec..a5275b63 100644
--- a/stream.h
+++ b/stream.h
@@ -192,7 +192,6 @@ val open_directory(val path);
val open_file(val path, val mode_str);
val open_fileno(val fd, val mode_str);
#if HAVE_SOCKETS
-val open_sockfd(val fd, val family, val type, val mode_str);
val open_socket(val family, val type, val mode_str);
#endif
val open_tail(val path, val mode_str, val seek_end_p);