/*
* ustcomm_close_unix_sock
*
- * Shutdown cleanly a unix socket.
+ * Close unix socket.
*
* Handles fd tracker internally.
*/
return ret;
}
+/*
+ * ustcomm_shutdown_unix_sock
+ *
+ * Shutdown unix socket. Keeps the file descriptor open, but shutdown
+ * communication.
+ */
+int ustcomm_shutdown_unix_sock(int sock)
+{
+ int ret;
+
+ ret = shutdown(sock, SHUT_RDWR);
+ if (ret) {
+ PERROR("Socket shutdown error");
+ ret = -errno;
+ }
+ return ret;
+}
+
/*
* ustcomm_recv_unix_sock
*
} while ((ret > 0 && ret < len_last) || (ret < 0 && errno == EINTR));
if (ret < 0) {
- int shutret;
-
if (errno != EPIPE && errno != ECONNRESET && errno != ECONNREFUSED)
PERROR("recvmsg");
ret = -errno;
if (ret == -ECONNRESET || ret == -ECONNREFUSED)
ret = -EPIPE;
- shutret = shutdown(sock, SHUT_RDWR);
- if (shutret)
- ERR("Socket shutdown error");
+ (void) ustcomm_shutdown_unix_sock(sock);
} else if (ret > 0) {
ret = len;
}
} while (ret < 0 && errno == EINTR);
if (ret < 0) {
- int shutret;
-
if (errno != EPIPE && errno != ECONNRESET)
PERROR("sendmsg");
ret = -errno;
if (ret == -ECONNRESET)
ret = -EPIPE;
- shutret = shutdown(sock, SHUT_RDWR);
- if (shutret)
- ERR("Socket shutdown error");
+ (void) ustcomm_shutdown_unix_sock(sock);
}
return ret;
int ustcomm_listen_unix_sock(int sock)
__attribute__((visibility("hidden")));
+int ustcomm_shutdown_unix_sock(int sock)
+ __attribute__((visibility("hidden")));
+
int ustcomm_close_unix_sock(int sock)
__attribute__((visibility("hidden")));