Remove old autovect-branch by moving to "dead" directory.
[official-gcc.git] / old-autovect-branch / libjava / gnu / java / net / natPlainSocketImplWin32.cc
blob48c7171c7c198049cfbedfb52af25aa3c3aa0a5d
1 /* Copyright (C) 2003, 2004, 2005 Free Software Foundation
3 This file is part of libgcj.
5 This software is copyrighted work licensed under the terms of the
6 Libgcj License. Please consult the file "LIBGCJ_LICENSE" for
7 details. */
9 #include <config.h>
10 #include <platform.h>
12 #undef STRICT
13 #undef MAX_PRIORITY
14 #undef MIN_PRIORITY
16 #include <gnu/java/net/PlainSocketImpl.h>
17 #include <gnu/java/net/PlainSocketImpl$SocketInputStream.h>
18 #include <gnu/java/net/PlainSocketImpl$SocketOutputStream.h>
19 #include <java/io/IOException.h>
20 #include <java/net/BindException.h>
21 #include <java/net/ConnectException.h>
22 #include <java/net/InetAddress.h>
23 #include <java/net/InetSocketAddress.h>
24 #include <java/net/SocketException.h>
25 #include <java/net/SocketTimeoutException.h>
26 #include <java/lang/InternalError.h>
27 #include <java/lang/Object.h>
28 #include <java/lang/Boolean.h>
29 #include <java/lang/Class.h>
30 #include <java/lang/Integer.h>
31 #include <java/lang/Thread.h>
32 #include <java/lang/NullPointerException.h>
33 #include <java/lang/ArrayIndexOutOfBoundsException.h>
34 #include <java/lang/IllegalArgumentException.h>
36 union SockAddr
38 struct sockaddr_in address;
39 #ifdef HAVE_INET6
40 struct sockaddr_in6 address6;
41 #endif
44 void
45 gnu::java::net::PlainSocketImpl::create (jboolean stream)
47 SOCKET sock = ::socket (AF_INET, stream ? SOCK_STREAM : SOCK_DGRAM, 0);
49 if (sock == INVALID_SOCKET)
51 _Jv_ThrowIOException ();
54 // Cast this to a HANDLE so we can make
55 // it non-inheritable via _Jv_platform_close_on_exec.
56 HANDLE hSocket = (HANDLE) sock;
57 _Jv_platform_close_on_exec (hSocket);
59 // We use native_fd in place of fd here. From leaving fd null we avoid
60 // the double close problem in FileDescriptor.finalize.
61 native_fd = (jint) hSocket;
64 void
65 gnu::java::net::PlainSocketImpl::bind (::java::net::InetAddress *host, jint lport)
67 union SockAddr u;
68 struct sockaddr *ptr = (struct sockaddr *) &u.address;
69 jbyteArray haddress = host->addr;
70 jbyte *bytes = elements (haddress);
71 int len = haddress->length;
73 if (len == 4)
75 u.address.sin_family = AF_INET;
77 if (host != NULL)
78 memcpy (&u.address.sin_addr, bytes, len);
79 else
80 u.address.sin_addr.s_addr = htonl (INADDR_ANY);
82 len = sizeof (struct sockaddr_in);
83 u.address.sin_port = htons (lport);
85 #ifdef HAVE_INET6
86 else if (len == 16)
88 u.address6.sin6_family = AF_INET6;
89 memcpy (&u.address6.sin6_addr, bytes, len);
90 len = sizeof (struct sockaddr_in6);
91 u.address6.sin6_port = htons (lport);
93 #endif
94 else
95 throw new ::java::net::SocketException (JvNewStringUTF ("invalid length"));
97 if (::bind (native_fd, ptr, len) != SOCKET_ERROR)
99 socklen_t addrlen = sizeof(u);
101 if (lport != 0)
102 localport = lport;
103 else if (::getsockname (native_fd, (sockaddr*) &u, &addrlen) != SOCKET_ERROR)
104 localport = ntohs (u.address.sin_port);
105 else
106 goto error;
108 return;
111 error:
112 DWORD dwErrorCode = WSAGetLastError ();
113 throw new ::java::net::BindException (_Jv_WinStrError (dwErrorCode));
116 static void
117 throwConnectException (DWORD dwErrorCode)
119 throw new ::java::net::ConnectException (_Jv_WinStrError (dwErrorCode));
122 static void
123 throwConnectException ()
125 throwConnectException (WSAGetLastError ());
128 void
129 gnu::java::net::PlainSocketImpl::connect (::java::net::SocketAddress *addr,
130 jint timeout)
132 ::java::net::InetSocketAddress *tmp = (::java::net::InetSocketAddress*) addr;
133 ::java::net::InetAddress *host = tmp->getAddress();
134 jint rport = tmp->getPort();
136 union SockAddr u;
137 socklen_t addrlen = sizeof(u);
138 jbyteArray haddress = host->addr;
139 jbyte *bytes = elements (haddress);
140 int len = haddress->length;
141 struct sockaddr *ptr = (struct sockaddr *) &u.address;
143 if (len == 4)
145 u.address.sin_family = AF_INET;
146 memcpy (&u.address.sin_addr, bytes, len);
147 len = sizeof (struct sockaddr_in);
148 u.address.sin_port = htons (rport);
150 #ifdef HAVE_INET6
151 else if (len == 16)
153 u.address6.sin6_family = AF_INET6;
154 memcpy (&u.address6.sin6_addr, bytes, len);
155 len = sizeof (struct sockaddr_in6);
156 u.address6.sin6_port = htons (rport);
158 #endif
159 else
160 throw new ::java::net::SocketException (JvNewStringUTF ("invalid length"));
162 if (timeout > 0)
164 // FIXME: we're creating a fresh WSAEVENT for each connect().
165 WSAEventWrapper aWSAEventWrapper(native_fd, FD_CONNECT);
166 WSAEVENT hEvent = aWSAEventWrapper.getEventHandle ();
168 if (::connect (native_fd, ptr, len) == SOCKET_ERROR)
170 if (WSAGetLastError () != WSAEWOULDBLOCK)
171 throwConnectException ();
173 DWORD dwRet =
174 WSAWaitForMultipleEvents (1, &hEvent, true, timeout, false);
175 // use true, false instead of TRUE, FALSE because the
176 // MS constants got undefined
178 // Reset and ignore our thread's interrupted flag.
179 // It's not possible to interrupt these sort of
180 // operations on Win32 anyway.
181 ::java::lang::Thread::interrupted();
183 if (dwRet == WSA_WAIT_FAILED)
184 throwConnectException ();
185 else if (dwRet == WSA_WAIT_TIMEOUT)
186 throw new ::java::net::SocketTimeoutException
187 (JvNewStringUTF ("connect timed out"));
189 // If we get here, we still need to check whether the actual
190 // connect() succeeded. Use any socket-specific error code
191 // instead of the thread-based one.
192 int nErrCode; int nErrLen=sizeof(nErrCode);
193 if (::getsockopt(native_fd, SOL_SOCKET, SO_ERROR, (char*) &nErrCode,
194 &nErrLen) == SOCKET_ERROR)
196 throwConnectException ();
199 if (nErrCode != NO_ERROR)
201 throwConnectException (nErrCode);
205 else
207 if (::connect (native_fd, ptr, len) == SOCKET_ERROR)
208 throwConnectException();
211 address = host;
212 port = rport;
214 // A bind may not have been done on this socket; if so, set localport now.
215 if (localport == 0)
217 if (::getsockname (native_fd, (sockaddr*) &u, &addrlen) != SOCKET_ERROR)
218 localport = ntohs (u.address.sin_port);
219 else
220 throwConnectException();
224 void
225 gnu::java::net::PlainSocketImpl::listen (jint backlog)
227 if (::listen (native_fd, backlog) == SOCKET_ERROR)
229 _Jv_ThrowIOException ();
233 void
234 gnu::java::net::PlainSocketImpl::accept (gnu::java::net::PlainSocketImpl *s)
236 union SockAddr u;
237 socklen_t addrlen = sizeof(u);
238 HANDLE hSocket = 0;
239 SOCKET new_socket = 0;
241 if (timeout > 0)
243 // FIXME: we're creating a fresh WSAEVENT for each accept().
244 // One possible alternative would be that native_fd really points
245 // to an extended structure consisting of the SOCKET, its
246 // associated WSAEVENT, etc.
247 WSAEventWrapper aWSAEventWrapper(native_fd, FD_ACCEPT);
248 WSAEVENT hEvent = aWSAEventWrapper.getEventHandle ();
250 for (;;)
252 new_socket = ::accept (native_fd, (sockaddr*) &u, &addrlen);
254 if (new_socket != INVALID_SOCKET)
256 // This new child socket is nonblocking because the parent
257 // socket became nonblocking via the WSAEventSelect() call,
258 // so we set its mode back to blocking.
259 WSAEventSelect (new_socket, hEvent, 0);
260 // undo the hEvent <-> FD_ACCEPT association inherited
261 // inherited from our parent socket
263 unsigned long lSockOpt = 0L;
264 // blocking mode
265 if (ioctlsocket(new_socket, FIONBIO, &lSockOpt) == SOCKET_ERROR)
267 goto error;
269 break;
271 else if (WSAGetLastError () != WSAEWOULDBLOCK)
273 goto error;
276 DWORD dwRet =
277 WSAWaitForMultipleEvents (1, &hEvent, true, timeout, false);
278 // use true, false instead of TRUE, FALSE because the
279 // MS constants got undefined
281 // Reset and ignore our thread's interrupted flag.
282 ::java::lang::Thread::interrupted();
284 if (dwRet == WSA_WAIT_FAILED)
285 goto error;
286 else if (dwRet == WSA_WAIT_TIMEOUT)
287 throw new ::java::net::SocketTimeoutException
288 (JvNewStringUTF ("Accept timed out"));
291 else
293 new_socket = ::accept (native_fd, (sockaddr*) &u, &addrlen);
296 if (new_socket == INVALID_SOCKET)
297 goto error;
299 // Cast this to a HANDLE so we can make
300 // it non-inheritable via _Jv_platform_close_on_exec.
301 hSocket = (HANDLE) new_socket;
302 _Jv_platform_close_on_exec (hSocket);
304 jbyteArray raddr;
305 jint rport;
306 if (u.address.sin_family == AF_INET)
308 raddr = JvNewByteArray (4);
309 memcpy (elements (raddr), &u.address.sin_addr, 4);
310 rport = ntohs (u.address.sin_port);
312 #ifdef HAVE_INET6
313 else if (u.address.sin_family == AF_INET6)
315 raddr = JvNewByteArray (16);
316 memcpy (elements (raddr), &u.address6.sin6_addr, 16);
317 rport = ntohs (u.address6.sin6_port);
319 #endif
320 else
321 throw new ::java::net::SocketException (JvNewStringUTF ("invalid family"));
323 s->native_fd = (jint) hSocket;
324 s->localport = localport;
325 s->address = new ::java::net::InetAddress (raddr, NULL);
326 s->port = rport;
327 return;
329 error:
330 _Jv_ThrowIOException ();
333 // Close(shutdown) the socket.
334 void
335 gnu::java::net::PlainSocketImpl::close()
337 // Avoid races from asynchronous finalization.
338 JvSynchronize sync (this);
340 // should we use shutdown here? how would that effect so_linger?
341 int res = ::closesocket (native_fd);
343 if (res == -1)
345 // These three errors are not errors according to tests performed
346 // on the reference implementation.
347 DWORD dwErr = WSAGetLastError();
348 if (dwErr != WSAENOTCONN && dwErr != WSAECONNRESET
349 && dwErr != WSAENOTSOCK)
350 _Jv_ThrowIOException ();
352 // Safe place to reset the file pointer.
353 native_fd = -1;
354 timeout = 0;
357 // Write a byte to the socket.
358 void
359 gnu::java::net::PlainSocketImpl$SocketOutputStream::write(jint b)
361 jbyte d =(jbyte) b;
362 int r = 0;
364 while (r != 1)
366 r = ::send (this$0->native_fd, (char*) &d, 1, 0);
367 if (r == -1)
369 DWORD dwErr = WSAGetLastError();
371 // Reset and ignore our thread's interrupted flag.
372 // It's not possible to interrupt these sort of
373 // operations on Win32 anyway.
374 ::java::lang::Thread::interrupted();
376 // Some errors should not cause exceptions.
377 if (dwErr != WSAENOTCONN && dwErr != WSAECONNRESET
378 && dwErr != WSAENOTSOCK)
379 _Jv_ThrowIOException ();
380 break;
385 // Write some bytes to the socket.
386 void
387 gnu::java::net::PlainSocketImpl$SocketOutputStream::write(jbyteArray b,
388 jint offset, jint len)
390 if (! b)
391 throw new ::java::lang::NullPointerException;
392 if (offset < 0 || len < 0 || offset + len > JvGetArrayLength (b))
393 throw new ::java::lang::ArrayIndexOutOfBoundsException;
395 jbyte *bytes = elements (b) + offset;
396 int written = 0;
397 while (len > 0)
399 int r = ::send (this$0->native_fd, (char*) bytes, len, 0);
401 if (r == -1)
403 DWORD dwErr = WSAGetLastError();
405 // Reset and ignore our thread's interrupted flag.
406 ::java::lang::Thread::interrupted();
408 // Some errors should not cause exceptions.
409 if (dwErr != WSAENOTCONN && dwErr != WSAECONNRESET
410 && dwErr != WSAENOTSOCK)
411 _Jv_ThrowIOException ();
412 break;
415 written += r;
416 len -= r;
417 bytes += r;
421 void
422 gnu::java::net::PlainSocketImpl::sendUrgentData (jint)
424 throw new ::java::net::SocketException (JvNewStringLatin1 (
425 "PlainSocketImpl: sending of urgent data not supported by this socket"));
428 // read() helper
429 static jint
430 doRead(int native_fd, void* buf, int count, int timeout)
432 int r = 0;
433 DWORD dwErrorCode = 0;
434 // we are forced to declare this here because
435 // a call to Thread::interrupted() blanks out
436 // WSAGetLastError().
438 // FIXME: we unconditionally set SO_RCVTIMEO here
439 // because we can't detect whether someone has
440 // gone from a non-zero to zero timeout. What we'd
441 // really need is a member state variable in addition
442 // to timeout
443 int nRet= ::setsockopt(native_fd, SOL_SOCKET, SO_RCVTIMEO,
444 (char*)&timeout, sizeof(timeout));
445 if (nRet != NO_ERROR)
447 dwErrorCode = WSAGetLastError ();
448 goto error;
451 r = ::recv (native_fd, (char*) buf, count, 0);
453 if (r == 0)
454 return -1;
456 dwErrorCode = WSAGetLastError ();
457 // save WSAGetLastError() before calling Thread.interrupted()
459 // Reset and ignore our thread's interrupted flag.
460 ::java::lang::Thread::interrupted();
462 if (r == -1)
464 error:
465 // Some errors cause us to return end of stream...
466 if (dwErrorCode == WSAENOTCONN)
467 return -1;
469 // Other errors need to be signalled.
470 if (dwErrorCode == WSAETIMEDOUT)
471 throw new ::java::net::SocketTimeoutException
472 (JvNewStringUTF ("Read timed out") );
473 else
474 _Jv_ThrowIOException (dwErrorCode);
477 return r;
480 // Read a single byte from the socket.
481 jint
482 gnu::java::net::PlainSocketImpl$SocketInputStream::read(void)
484 jbyte b;
485 doRead(this$0->native_fd, &b, 1, this$0->timeout);
486 return b & 0xFF;
489 // Read count bytes into the buffer, starting at offset.
490 jint
491 gnu::java::net::PlainSocketImpl$SocketInputStream::read(jbyteArray buffer,
492 jint offset, jint count)
494 // If zero bytes were requested, short circuit so that recv
495 // doesn't signal EOF.
496 if (count == 0)
497 return 0;
499 if (! buffer)
500 throw new ::java::lang::NullPointerException;
502 jsize bsize = JvGetArrayLength (buffer);
504 if (offset < 0 || count < 0 || offset + count > bsize)
505 throw new ::java::lang::ArrayIndexOutOfBoundsException;
507 jbyte *bytes = elements (buffer) + offset;
509 // Read the socket.
510 return doRead(this$0->native_fd, bytes, count, this$0->timeout);
513 // How many bytes are available?
514 jint
515 gnu::java::net::PlainSocketImpl::available(void)
517 unsigned long num = 0;
519 if (::ioctlsocket (native_fd, FIONREAD, &num) == SOCKET_ERROR)
520 _Jv_ThrowIOException ();
522 return (jint) num;
525 void
526 gnu::java::net::PlainSocketImpl::setOption (jint optID, ::java::lang::Object *value)
528 int val;
529 socklen_t val_len = sizeof (val);
531 if (native_fd < 0)
532 throw new ::java::net::SocketException (JvNewStringUTF ("Socket closed"));
534 if (_Jv_IsInstanceOf (value, &::java::lang::Boolean::class$))
536 ::java::lang::Boolean *boolobj =
537 static_cast< ::java::lang::Boolean *> (value);
538 if (boolobj->booleanValue())
539 val = 1;
540 else
542 if (optID == _Jv_SO_LINGER_)
543 val = -1;
544 else
545 val = 0;
548 else if (_Jv_IsInstanceOf (value, &::java::lang::Integer::class$))
550 ::java::lang::Integer *intobj =
551 static_cast< ::java::lang::Integer *> (value);
552 val = (int) intobj->intValue();
554 else
556 throw new ::java::lang::IllegalArgumentException (
557 JvNewStringLatin1 ("`value' must be Boolean or Integer"));
560 switch (optID)
562 case _Jv_TCP_NODELAY_ :
563 if (::setsockopt (native_fd, IPPROTO_TCP, TCP_NODELAY, (char *) &val,
564 val_len) == SOCKET_ERROR)
565 goto error;
566 return;
568 case _Jv_SO_KEEPALIVE_ :
569 if (::setsockopt (native_fd, SOL_SOCKET, SO_KEEPALIVE, (char *) &val,
570 val_len) == SOCKET_ERROR)
571 goto error;
572 break;
574 case _Jv_SO_BROADCAST_ :
575 throw new ::java::net::SocketException
576 (JvNewStringUTF ("SO_BROADCAST not valid for TCP"));
577 break;
579 case _Jv_SO_OOBINLINE_ :
580 if (::setsockopt (native_fd, SOL_SOCKET, SO_OOBINLINE, (char *) &val,
581 val_len) == SOCKET_ERROR)
582 goto error;
583 break;
585 case _Jv_SO_LINGER_ :
586 struct linger l_val;
587 l_val.l_onoff = (val != -1);
588 l_val.l_linger = val;
590 if (::setsockopt (native_fd, SOL_SOCKET, SO_LINGER, (char *) &l_val,
591 sizeof(l_val)) == SOCKET_ERROR)
592 goto error;
593 return;
595 case _Jv_SO_SNDBUF_ :
596 case _Jv_SO_RCVBUF_ :
597 int opt;
598 optID == _Jv_SO_SNDBUF_ ? opt = SO_SNDBUF : opt = SO_RCVBUF;
599 if (::setsockopt (native_fd, SOL_SOCKET, opt, (char *) &val,
600 val_len) == SOCKET_ERROR)
601 goto error;
602 return;
604 case _Jv_SO_BINDADDR_ :
605 throw new ::java::net::SocketException (
606 JvNewStringUTF ("SO_BINDADDR: read only option"));
607 return;
609 case _Jv_IP_MULTICAST_IF_ :
610 throw new ::java::net::SocketException (
611 JvNewStringUTF ("IP_MULTICAST_IF: not valid for TCP"));
612 return;
614 case _Jv_IP_MULTICAST_IF2_ :
615 throw new ::java::net::SocketException (
616 JvNewStringUTF ("IP_MULTICAST_IF2: not valid for TCP"));
617 break;
619 case _Jv_IP_MULTICAST_LOOP_ :
620 throw new ::java::net::SocketException (
621 JvNewStringUTF ("IP_MULTICAST_LOOP: not valid for TCP"));
622 break;
624 case _Jv_IP_TOS_ :
625 if (::setsockopt (native_fd, SOL_SOCKET, IP_TOS, (char *) &val,
626 val_len) == SOCKET_ERROR)
627 goto error;
628 break;
630 case _Jv_SO_REUSEADDR_ :
631 throw new ::java::net::SocketException (
632 JvNewStringUTF ("SO_REUSEADDR: not valid for TCP"));
633 return;
635 case _Jv_SO_TIMEOUT_ :
636 timeout = val;
637 return;
639 default :
640 WSASetLastError (WSAENOPROTOOPT);
643 error:
644 _Jv_ThrowSocketException ();
647 ::java::lang::Object *
648 gnu::java::net::PlainSocketImpl::getOption (jint optID)
650 int val;
651 socklen_t val_len = sizeof(val);
652 union SockAddr u;
653 socklen_t addrlen = sizeof(u);
654 struct linger l_val;
655 socklen_t l_val_len = sizeof(l_val);
657 switch (optID)
659 case _Jv_TCP_NODELAY_ :
660 if (::getsockopt (native_fd, IPPROTO_TCP, TCP_NODELAY, (char *) &val,
661 &val_len) == SOCKET_ERROR)
662 goto error;
663 else
664 return new ::java::lang::Boolean (val != 0);
665 break;
667 case _Jv_SO_LINGER_ :
668 if (::getsockopt (native_fd, SOL_SOCKET, SO_LINGER, (char *) &l_val,
669 &l_val_len) == SOCKET_ERROR)
670 goto error;
672 if (l_val.l_onoff)
673 return new ::java::lang::Integer (l_val.l_linger);
674 else
675 return new ::java::lang::Boolean ((jboolean)false);
676 break;
678 case _Jv_SO_KEEPALIVE_ :
679 if (::getsockopt (native_fd, SOL_SOCKET, SO_KEEPALIVE, (char *) &val,
680 &val_len) == SOCKET_ERROR)
681 goto error;
682 else
683 return new ::java::lang::Boolean (val != 0);
685 case _Jv_SO_BROADCAST_ :
686 if (::getsockopt (native_fd, SOL_SOCKET, SO_BROADCAST, (char *) &val,
687 &val_len) == SOCKET_ERROR)
688 goto error;
689 return new ::java::lang::Boolean ((jboolean)val);
691 case _Jv_SO_OOBINLINE_ :
692 if (::getsockopt (native_fd, SOL_SOCKET, SO_OOBINLINE, (char *) &val,
693 &val_len) == SOCKET_ERROR)
694 goto error;
695 return new ::java::lang::Boolean ((jboolean)val);
697 case _Jv_SO_RCVBUF_ :
698 case _Jv_SO_SNDBUF_ :
699 int opt;
700 optID == _Jv_SO_SNDBUF_ ? opt = SO_SNDBUF : opt = SO_RCVBUF;
701 if (::getsockopt (native_fd, SOL_SOCKET, opt, (char *) &val,
702 &val_len) == SOCKET_ERROR)
703 goto error;
704 else
705 return new ::java::lang::Integer (val);
706 break;
707 case _Jv_SO_BINDADDR_:
708 // cache the local address
709 if (localAddress == NULL)
711 jbyteArray laddr;
713 if (::getsockname (native_fd, (sockaddr*) &u,
714 &addrlen) == SOCKET_ERROR)
715 goto error;
717 if (u.address.sin_family == AF_INET)
719 laddr = JvNewByteArray (4);
720 memcpy (elements (laddr), &u.address.sin_addr, 4);
722 #ifdef HAVE_INET6
723 else if (u.address.sin_family == AF_INET6)
725 laddr = JvNewByteArray (16);
726 memcpy (elements (laddr), &u.address6.sin6_addr, 16);
728 #endif
729 else
730 throw new ::java::net::SocketException
731 (JvNewStringUTF ("invalid family"));
732 localAddress = new ::java::net::InetAddress (laddr, NULL);
735 return localAddress;
736 break;
737 case _Jv_IP_MULTICAST_IF_ :
738 throw new ::java::net::SocketException
739 (JvNewStringUTF ("IP_MULTICAST_IF: not valid for TCP"));
740 break;
742 case _Jv_IP_MULTICAST_IF2_ :
743 throw new ::java::net::SocketException
744 (JvNewStringUTF ("IP_MULTICAST_IF2: not valid for TCP"));
745 break;
747 case _Jv_IP_MULTICAST_LOOP_ :
748 throw new ::java::net::SocketException
749 (JvNewStringUTF ("IP_MULTICAST_LOOP: not valid for TCP"));
750 break;
752 case _Jv_IP_TOS_ :
753 if (::getsockopt (native_fd, SOL_SOCKET, IP_TOS, (char *) &val,
754 &val_len) == SOCKET_ERROR)
755 goto error;
756 return new ::java::lang::Integer (val);
757 break;
759 case _Jv_SO_REUSEADDR_ :
760 throw new ::java::net::SocketException
761 (JvNewStringUTF ("SO_REUSEADDR: not valid for TCP"));
762 break;
764 case _Jv_SO_TIMEOUT_ :
765 return new ::java::lang::Integer (timeout);
766 break;
768 default :
769 WSASetLastError (WSAENOPROTOOPT);
772 error:
773 _Jv_ThrowSocketException ();
774 return 0;
775 // we should never get here
778 void
779 gnu::java::net::PlainSocketImpl::shutdownInput (void)
781 if (::shutdown (native_fd, 0))
782 _Jv_ThrowSocketException ();
785 void
786 gnu::java::net::PlainSocketImpl::shutdownOutput (void)
788 if (::shutdown (native_fd, 1))
789 _Jv_ThrowSocketException ();