Commit d0c97db6 by Michael Koch Committed by Michael Koch

2002-09-12 Michael Koch <konqueror@gmx.de>

	* java/net/DatagramSocketImpl.jav
	(peekData): New method.
	* java/net/PlainDatagramSocketImpl.java
	(peekData): New method.
	* java/net/natPlainDatagramSocketImpl.cc
	(peekData): New method.
	* java/net/URLConnection
	(getPermission): New method.
	(addRequestProperty): New method.
	(getRequestProperties): New method.
	(guessContentTypeFromStream): New method, not really implemented.
	(URLConnection): Added/updated documentation.
	(connect): Added/updated documentation.
	(getURL): Added/updated documentation.
	(getContentLength): Added/updated documentation.
	(getContentType: Added/updated documentation.
	(getContentEncoding): Added/updated documentation.
	(getExpiration): Added/updated documentation.
	(getDate): Added/updated documentation.
	(getLastModified): Added/updated documentation.
	(getHeaderField): Added/updated documentation.
	(getHeaderFields): Added/updated documentation.
	(getHeaderFieldInt): Added/updated documentation.
	(getHeaderFieldDate): Added/updated documentation.
	(getHeaderFieldKey): Added/updated documentation.
	(getContent): Added/updated documentation.
	(getInputStream): Added/updated documentation.
	(getOutputStream): Added/updated documentation.
	(toString): Added/updated documentation.
	(setDoInput): Added/updated documentation.
	(getDoInput): Added/updated documentation.
	(setDoOutput): Added/updated documentation.
	(getDoOutput): Added/updated documentation.
	(setAllowUserInteraction): Added/updated documentation.
	(getAllowUserInteraction): Added/updated documentation.
	(setDefaultAllowUserInteraction): Added/updated documentation.
	(getDefaultAllowUserInteraction): Added/updated documentation.
	(setUseCaches): Added/updated documentation.
	(getUseCaches): Added/updated documentation.
	(setIfModifiedSince): Added/updated documentation.
	(getIfModifiedSince): Added/updated documentation.
	(getDefaultUseCaches): Added/updated documentation.
	(setDefaultUseCaches): Added/updated documentation.
	(setRequestProperty): Added/updated documentation.
	(getRequestProperty): Added/updated documentation.
	(setDefaultRequestProperty): Added/updated documentation.
	(getDefaultRequestProperty): Added/updated documentation.
	(setContentHandlerFactory): Added/updated documentation.

From-SVN: r57049
parent 35aff10b
2002-09-12 Michael Koch <konqueror@gmx.de>
* java/net/DatagramSocketImpl.jav
(peekData): New method.
* java/net/PlainDatagramSocketImpl.java
(peekData): New method.
* java/net/natPlainDatagramSocketImpl.cc
(peekData): New method.
* java/net/URLConnection
(getPermission): New method.
(addRequestProperty): New method.
(getRequestProperties): New method.
(guessContentTypeFromStream): New method, not really implemented.
(URLConnection): Added/updated documentation.
(connect): Added/updated documentation.
(getURL): Added/updated documentation.
(getContentLength): Added/updated documentation.
(getContentType: Added/updated documentation.
(getContentEncoding): Added/updated documentation.
(getExpiration): Added/updated documentation.
(getDate): Added/updated documentation.
(getLastModified): Added/updated documentation.
(getHeaderField): Added/updated documentation.
(getHeaderFields): Added/updated documentation.
(getHeaderFieldInt): Added/updated documentation.
(getHeaderFieldDate): Added/updated documentation.
(getHeaderFieldKey): Added/updated documentation.
(getContent): Added/updated documentation.
(getInputStream): Added/updated documentation.
(getOutputStream): Added/updated documentation.
(toString): Added/updated documentation.
(setDoInput): Added/updated documentation.
(getDoInput): Added/updated documentation.
(setDoOutput): Added/updated documentation.
(getDoOutput): Added/updated documentation.
(setAllowUserInteraction): Added/updated documentation.
(getAllowUserInteraction): Added/updated documentation.
(setDefaultAllowUserInteraction): Added/updated documentation.
(getDefaultAllowUserInteraction): Added/updated documentation.
(setUseCaches): Added/updated documentation.
(getUseCaches): Added/updated documentation.
(setIfModifiedSince): Added/updated documentation.
(getIfModifiedSince): Added/updated documentation.
(getDefaultUseCaches): Added/updated documentation.
(setDefaultUseCaches): Added/updated documentation.
(setRequestProperty): Added/updated documentation.
(getRequestProperty): Added/updated documentation.
(setDefaultRequestProperty): Added/updated documentation.
(getDefaultRequestProperty): Added/updated documentation.
(setContentHandlerFactory): Added/updated documentation.
(guessContentTypeFromName): Added/updated documentation.
(getFileNameMap): Added/updated documentation.
(setFileNameMap): Added/updated documentation.
2002-09-11 Michael Koch <konqueror@gmx.de>
* java/net/Socket.java
......
......@@ -112,6 +112,20 @@ public abstract class DatagramSocketImpl implements SocketOptions
protected abstract int peek(InetAddress i) throws IOException;
/**
* Takes a peek at the next packet received. This packet is not consumed.
* With the next peekData/receive operation this packet will be read again.
*
* @param p The DatagramPacket to fill in with the data sent.
*
* @return The port number of the sender of the packet.
*
* @exception IOException If an error occurs
*
* @since 1.4
*/
protected abstract int peekData (DatagramPacket p) throws IOException;
/**
* Transmits the specified packet of data to the network. The destination
* host and port should be encoded in the packet.
*
......@@ -208,7 +222,7 @@ public abstract class DatagramSocketImpl implements SocketOptions
* Sets the specified option on a socket to the passed in object. For
* options that take an integer argument, the passed in object is an
* <code>Integer</code>. For options that are set to on or off, the
* value passed will be a <code>Boolean</code>. The <code>option_id</code>
* value passed will be a <code>Boolean</code>. The <code>option_id</code>
* parameter is one of the defined constants in the superinterface.
*
* @param option_id The identifier of the option
......@@ -221,9 +235,9 @@ public abstract class DatagramSocketImpl implements SocketOptions
throws SocketException;
/**
* Returns the current setting of the specified option. The
* <code>Object</code> returned will be an <code>Integer</code> for options
* that have integer values. For options that are set to on or off, a
* Returns the current setting of the specified option. The
* <code>Object</code> returned will be an <code>Integer</code> for options
* that have integer values. For options that are set to on or off, a
* <code>Boolean</code> will be returned. The <code>option_id</code>
* is one of the defined constants in the superinterface.
*
......
......@@ -65,6 +65,7 @@ class PlainDatagramSocketImpl extends DatagramSocketImpl
throws SocketException;
protected native void create() throws SocketException;
protected native int peek(InetAddress i) throws IOException;
protected native int peekData (DatagramPacket dp) throws IOException;
protected native void setTimeToLive(int ttl) throws IOException;
protected native int getTimeToLive() throws IOException;
protected native void send(DatagramPacket p) throws IOException;
......
......@@ -93,6 +93,13 @@ java::net::PlainDatagramSocketImpl::peek (java::net::InetAddress *)
JvNewStringLatin1 ("DatagramSocketImpl.peek: unimplemented"));
}
jint
java::net::PlainDatagramSocketImpl::peekData(java::net::DatagramPacket *)
{
throw new java::io::IOException (
JvNewStringLatin1 ("DatagramSocketImpl.peekData: unimplemented"));
}
void
java::net::PlainDatagramSocketImpl::close ()
{
......@@ -295,6 +302,68 @@ java::net::PlainDatagramSocketImpl::peek (java::net::InetAddress *i)
throw new java::io::IOException (JvNewStringUTF (strerr));
}
jint
java::net::PlainDatagramSocketImpl::peekData(java::net::DatagramPacket *p)
{
// FIXME: Deal with Multicast and if the socket is connected.
union SockAddr u;
socklen_t addrlen = sizeof(u);
jbyte *dbytes = elements (p->getData());
ssize_t retlen = 0;
// FIXME: implement timeout support for Win32
#ifndef WIN32
// Do timeouts via select since SO_RCVTIMEO is not always available.
if (timeout > 0 && fnum >= 0 && fnum < FD_SETSIZE)
{
fd_set rset;
struct timeval tv;
FD_ZERO(&rset);
FD_SET(fnum, &rset);
tv.tv_sec = timeout / 1000;
tv.tv_usec = (timeout % 1000) * 1000;
int retval;
if ((retval = _Jv_select (fnum + 1, &rset, NULL, NULL, &tv)) < 0)
goto error;
else if (retval == 0)
throw new java::io::InterruptedIOException ();
}
#endif /* WIN32 */
retlen =
::recvfrom (fnum, (char *) dbytes, p->getLength(), MSG_PEEK, (sockaddr*) &u,
&addrlen);
if (retlen < 0)
goto error;
// FIXME: Deal with Multicast addressing and if the socket is connected.
jbyteArray raddr;
jint rport;
if (u.address.sin_family == AF_INET)
{
raddr = JvNewByteArray (4);
memcpy (elements (raddr), &u.address.sin_addr, 4);
rport = ntohs (u.address.sin_port);
}
#ifdef HAVE_INET6
else if (u.address.sin_family == AF_INET6)
{
raddr = JvNewByteArray (16);
memcpy (elements (raddr), &u.address6.sin6_addr, 16);
rport = ntohs (u.address6.sin6_port);
}
#endif
else
throw new java::net::SocketException (JvNewStringUTF ("invalid family"));
p->setAddress (new InetAddress (raddr, NULL));
p->setPort (rport);
p->setLength ((jint) retlen);
return rport;
error:
char* strerr = strerror (errno);
throw new java::io::IOException (JvNewStringUTF (strerr));
}
// Close(shutdown) the socket.
void
java::net::PlainDatagramSocketImpl::close ()
......@@ -529,12 +598,12 @@ java::net::PlainDatagramSocketImpl::setOption (jint optID,
throw new java::net::SocketException (
JvNewStringUTF ("SO_KEEPALIVE not valid for UDP"));
return;
case _Jv_SO_BROADCAST_ :
if (::setsockopt (fnum, SOL_SOCKET, SO_BROADCAST, (char *) &val,
val_len) != 0)
goto error;
break;
break;
case _Jv_SO_OOBINLINE_ :
throw new java::net::SocketException (
......@@ -620,7 +689,7 @@ java::net::PlainDatagramSocketImpl::setOption (jint optID,
val_len) != 0)
goto error;
return;
case _Jv_SO_TIMEOUT_ :
timeout = val;
return;
......@@ -655,7 +724,7 @@ java::net::PlainDatagramSocketImpl::getOption (jint optID)
throw new java::net::SocketException (
JvNewStringUTF ("SO_KEEPALIVE not valid for UDP"));
break;
case _Jv_SO_BROADCAST_ :
if (::getsockopt (fnum, SOL_SOCKET, SO_BROADCAST, (char *) &val,
&val_len) != 0)
......@@ -665,8 +734,8 @@ java::net::PlainDatagramSocketImpl::getOption (jint optID)
case _Jv_SO_OOBINLINE_ :
throw new java::net::SocketException (
JvNewStringUTF ("SO_OOBINLINE not valid for UDP"));
break;
break;
case _Jv_SO_RCVBUF_ :
case _Jv_SO_SNDBUF_ :
#if defined(SO_SNDBUF) && defined(SO_RCVBUF)
......@@ -756,7 +825,7 @@ java::net::PlainDatagramSocketImpl::getOption (jint optID)
&val_len) != 0)
goto error;
return new java::lang::Integer (val);
default :
errno = ENOPROTOOPT;
}
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment