summaryrefslogtreecommitdiff
path: root/ext/socket
diff options
context:
space:
mode:
authormatz <matz@b2dd03c8-39d4-4d8f-98ff-823fe69b080e>2000-05-01 09:42:38 +0000
committermatz <matz@b2dd03c8-39d4-4d8f-98ff-823fe69b080e>2000-05-01 09:42:38 +0000
commitfedf48986da718580062d081dda38c4ee182c254 (patch)
tree65e06d76c544a8d80296d686bf88ec3af41fdc50 /ext/socket
parentacbb1c943457d3b8802f099ee0e34331bc78bd38 (diff)
2000-05-01
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@678 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
Diffstat (limited to 'ext/socket')
-rw-r--r--ext/socket/extconf.rb2
-rw-r--r--ext/socket/getaddrinfo.c4
-rw-r--r--ext/socket/socket.c45
3 files changed, 35 insertions, 16 deletions
diff --git a/ext/socket/extconf.rb b/ext/socket/extconf.rb
index 6a2937bb3f..1adb7cc1b5 100644
--- a/ext/socket/extconf.rb
+++ b/ext/socket/extconf.rb
@@ -6,6 +6,7 @@ case PLATFORM
when /mswin32/
test_func = "WSACleanup"
have_library("wsock32", "WSACleanup")
+ have_func("closesocket")
when /cygwin/
# $LDFLAGS << " -L/usr/lib" if File.directory?("/usr/lib")
# $CFLAGS << " -I/usr/include"
@@ -14,6 +15,7 @@ when /cygwin/
when /beos/
test_func = "socket"
have_library("net", "socket")
+ have_func("closesocket")
when /i386-os2_emx/
test_func = "socket"
have_library("socket", "socket")
diff --git a/ext/socket/getaddrinfo.c b/ext/socket/getaddrinfo.c
index 0b9d9b6afc..c312b92705 100644
--- a/ext/socket/getaddrinfo.c
+++ b/ext/socket/getaddrinfo.c
@@ -421,7 +421,11 @@ getaddrinfo(hostname, servname, hints, res)
s = socket(afd->a_af, SOCK_DGRAM, 0);
if (s < 0)
continue;
+#if defined(HAVE_CLOSESOCKET)
+ closesocket(s);
+#else
close(s);
+#endif
if (pai->ai_flags & AI_PASSIVE) {
GET_AI(cur->ai_next, afd, afd->a_addrany, port);
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);