summaryrefslogtreecommitdiff
path: root/ext/socket/socket.c
diff options
context:
space:
mode:
Diffstat (limited to 'ext/socket/socket.c')
-rw-r--r--ext/socket/socket.c45
1 files changed, 29 insertions, 16 deletions
diff --git a/ext/socket/socket.c b/ext/socket/socket.c
index aee13a1a19..2ad653cc4a 100644
--- a/ext/socket/socket.c
+++ b/ext/socket/socket.c
@@ -181,7 +181,7 @@ bsock_close_read(sock)
rb_thread_fd_close(fileno(fptr->f));
fptr->mode &= ~FMODE_READABLE;
#ifdef NT
- free(fptr->f);
+ myfdclose(fptr->f);
#else
fclose(fptr->f);
#endif
@@ -207,7 +207,7 @@ bsock_close_write(sock)
shutdown(fileno(fptr->f2), 1);
fptr->mode &= ~FMODE_WRITABLE;
#ifdef NT
- free(fptr->f2);
+ myfdclose(fptr->f2);
#else
fclose(fptr->f2);
#endif
@@ -256,7 +256,8 @@ bsock_getsockopt(sock, lev, optname)
VALUE sock, lev, optname;
{
#if !defined(__BEOS__)
- int level, option, len;
+ int level, option;
+ socklen_t len;
char *buf;
OpenFile *fptr;
@@ -280,7 +281,7 @@ bsock_getsockname(sock)
VALUE sock;
{
char buf[1024];
- int len = sizeof buf;
+ socklen_t len = sizeof buf;
OpenFile *fptr;
GetOpenFile(sock, fptr);
@@ -294,7 +295,7 @@ bsock_getpeername(sock)
VALUE sock;
{
char buf[1024];
- int len = sizeof buf;
+ socklen_t len = sizeof buf;
OpenFile *fptr;
GetOpenFile(sock, fptr);
@@ -374,9 +375,9 @@ s_recv(sock, argc, argv, from)
OpenFile *fptr;
VALUE str;
char buf[1024];
- int fd, alen = sizeof buf;
+ socklen_t alen = sizeof buf;
VALUE len, flg;
- int flags;
+ int fd, flags;
rb_scan_args(argc, argv, "11", &len, &flg);
@@ -763,7 +764,11 @@ open_inet(class, h, serv, type)
}
if (status < 0) {
+#if defined(HAVE_CLOSESOCKET)
+ closesocket(fd);
+#else
close(fd);
+#endif
fd = -1;
continue;
} else
@@ -771,7 +776,11 @@ open_inet(class, h, serv, type)
}
if (status < 0) {
if (fd >= 0)
+#if defined(HAVE_CLOSESOCKET)
+ closesocket(fd);
+#else
close(fd);
+#endif
freeaddrinfo(res0);
rb_sys_fail(syscall);
}
@@ -956,7 +965,7 @@ s_accept(class, fd, sockaddr, len)
VALUE class;
int fd;
struct sockaddr *sockaddr;
- int *len;
+ socklen_t *len;
{
int fd2;
@@ -989,7 +998,7 @@ tcp_accept(sock)
{
OpenFile *fptr;
struct sockaddr_storage from;
- int fromlen;
+ socklen_t fromlen;
GetOpenFile(sock, fptr);
fromlen = sizeof(from);
@@ -1037,7 +1046,11 @@ open_unix(class, path, server)
}
if (status < 0) {
+#if defined(HAVE_CLOSESOCKET)
+ closesocket(fd);
+#else
close(fd);
+#endif
rb_sys_fail(sockaddr.sun_path);
}
@@ -1057,7 +1070,7 @@ ip_addr(sock)
{
OpenFile *fptr;
struct sockaddr_storage addr;
- int len = sizeof addr;
+ socklen_t len = sizeof addr;
GetOpenFile(sock, fptr);
@@ -1072,7 +1085,7 @@ ip_peeraddr(sock)
{
OpenFile *fptr;
struct sockaddr_storage addr;
- int len = sizeof addr;
+ socklen_t len = sizeof addr;
GetOpenFile(sock, fptr);
@@ -1231,7 +1244,7 @@ unix_path(sock)
GetOpenFile(sock, fptr);
if (fptr->path == 0) {
struct sockaddr_un addr;
- int len = sizeof(addr);
+ socklen_t len = sizeof(addr);
if (getsockname(fileno(fptr->f), (struct sockaddr*)&addr, &len) < 0)
rb_sys_fail(0);
fptr->path = strdup(addr.sun_path);
@@ -1261,7 +1274,7 @@ unix_accept(sock)
{
OpenFile *fptr;
struct sockaddr_un from;
- int fromlen;
+ socklen_t fromlen;
GetOpenFile(sock, fptr);
fromlen = sizeof(struct sockaddr_un);
@@ -1282,7 +1295,7 @@ unix_addr(sock)
{
OpenFile *fptr;
struct sockaddr_un addr;
- int len = sizeof addr;
+ socklen_t len = sizeof addr;
GetOpenFile(sock, fptr);
@@ -1297,7 +1310,7 @@ unix_peeraddr(sock)
{
OpenFile *fptr;
struct sockaddr_un addr;
- int len = sizeof addr;
+ socklen_t len = sizeof addr;
GetOpenFile(sock, fptr);
@@ -1500,7 +1513,7 @@ sock_accept(sock)
OpenFile *fptr;
VALUE sock2;
char buf[1024];
- int len = sizeof buf;
+ socklen_t len = sizeof buf;
GetOpenFile(sock, fptr);
sock2 = s_accept(rb_cSocket,fileno(fptr->f),(struct sockaddr*)buf,&len);