aboutsummaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorAndreas Schneider <asn@cryptomilk.org>2011-09-17 18:58:30 +0200
committerAndreas Schneider <asn@cryptomilk.org>2011-09-18 21:37:17 +0200
commitc2686b8febf2c57761cfa9e47c8dc533f84d1cb2 (patch)
tree9a5382c6a2a2c253da279a824d696ad2cdc61579 /src
parente7009fe8f3928db009f5d03ff47bd159599e5440 (diff)
downloadlibssh-c2686b8febf2c57761cfa9e47c8dc533f84d1cb2.tar.gz
libssh-c2686b8febf2c57761cfa9e47c8dc533f84d1cb2.tar.xz
libssh-c2686b8febf2c57761cfa9e47c8dc533f84d1cb2.zip
socket: Move socket function to right location.
Diffstat (limited to 'src')
-rw-r--r--src/connect.c26
-rw-r--r--src/socket.c23
2 files changed, 25 insertions, 24 deletions
diff --git a/src/connect.c b/src/connect.c
index 963971c8..a47c652c 100644
--- a/src/connect.c
+++ b/src/connect.c
@@ -84,16 +84,6 @@
#endif
#ifdef _WIN32
-void ssh_sock_set_nonblocking(socket_t sock) {
- u_long nonblocking = 1;
- ioctlsocket(sock, FIONBIO, &nonblocking);
-}
-
-void ssh_sock_set_blocking(socket_t sock) {
- u_long nonblocking = 0;
- ioctlsocket(sock, FIONBIO, &nonblocking);
-}
-
#ifndef gai_strerror
char WSAAPI *gai_strerrorA(int code) {
static char buf[256];
@@ -103,16 +93,6 @@ char WSAAPI *gai_strerrorA(int code) {
return buf;
}
#endif /* gai_strerror */
-
-#else /* _WIN32 */
-void ssh_sock_set_nonblocking(socket_t sock) {
- fcntl(sock, F_SETFL, O_NONBLOCK);
-}
-
-void ssh_sock_set_blocking(socket_t sock) {
- fcntl(sock, F_SETFL, 0);
-}
-
#endif /* _WIN32 */
static int ssh_connect_socket_close(socket_t s){
@@ -168,7 +148,7 @@ static int ssh_connect_ai_timeout(ssh_session session, const char *host,
*/
timeout_ms=timeout * 1000 + usec / 1000;
- ssh_sock_set_nonblocking(s);
+ ssh_socket_set_nonblocking(s);
ssh_log(session, SSH_LOG_RARE, "Trying to connect to host: %s:%d with "
"timeout %d ms", host, port, timeout_ms);
@@ -215,7 +195,7 @@ static int ssh_connect_ai_timeout(ssh_session session, const char *host,
/* s is connected ? */
ssh_log(session, SSH_LOG_PACKET, "Socket connected with timeout\n");
- ssh_sock_set_blocking(s);
+ ssh_socket_set_blocking(s);
leave_function();
return s;
@@ -385,7 +365,7 @@ socket_t ssh_connect_host_nonblocking(ssh_session session, const char *host,
continue;
}
}
- ssh_sock_set_nonblocking(s);
+ ssh_socket_set_nonblocking(s);
connect(s, itr->ai_addr, itr->ai_addrlen);
break;
diff --git a/src/socket.c b/src/socket.c
index a4a16b13..5bde8365 100644
--- a/src/socket.c
+++ b/src/socket.c
@@ -300,7 +300,7 @@ int ssh_socket_pollcallback(struct ssh_poll_handle_struct *p, socket_t fd, int r
ssh_log(s->session,SSH_LOG_PACKET,"Received POLLOUT in connecting state");
s->state = SSH_SOCKET_CONNECTED;
ssh_poll_set_events(p,POLLOUT | POLLIN);
- ssh_sock_set_blocking(ssh_socket_get_fd_in(s));
+ ssh_socket_set_blocking(ssh_socket_get_fd_in(s));
if(s->callbacks && s->callbacks->connected)
s->callbacks->connected(SSH_SOCKET_CONNECTED_OK,0,s->callbacks->userdata);
return 0;
@@ -701,6 +701,27 @@ int ssh_socket_get_status(ssh_socket s) {
return r;
}
+#ifdef _WIN32
+void ssh_socket_set_nonblocking(socket_t fd) {
+ u_long nonblocking = 1;
+ ioctlsocket(fd, FIONBIO, &nonblocking);
+}
+
+void ssh_socket_set_blocking(socket_t fd) {
+ u_long nonblocking = 0;
+ ioctlsocket(fd, FIONBIO, &nonblocking);
+}
+
+#else /* _WIN32 */
+void ssh_socket_set_nonblocking(socket_t fd) {
+ fcntl(fd, F_SETFL, O_NONBLOCK);
+}
+
+void ssh_socket_set_blocking(socket_t fd) {
+ fcntl(fd, F_SETFL, 0);
+}
+#endif /* _WIN32 */
+
/**
* @internal
* @brief Launches a socket connection