OpenCores
URL https://opencores.org/ocsvn/openrisc/openrisc/trunk

Subversion Repositories openrisc

[/] [openrisc/] [trunk/] [gnu-dev/] [or1k-gcc/] [libjava/] [classpath/] [vm/] [reference/] [gnu/] [java/] [net/] [VMPlainDatagramSocketImpl.java] - Blame information for rev 780

Details | Compare with Previous | View Log

Line No. Rev Author Line
1 780 jeremybenn
/* PlainDatagramSocketImpl.java -- VM interface for DatagramSocket impl
2
   Copyright (C) 2005 Free Software Foundation, Inc.
3
 
4
This file is part of GNU Classpath.
5
 
6
GNU Classpath is free software; you can redistribute it and/or modify
7
it under the terms of the GNU General Public License as published by
8
the Free Software Foundation; either version 2, or (at your option)
9
any later version.
10
 
11
GNU Classpath is distributed in the hope that it will be useful, but
12
WITHOUT ANY WARRANTY; without even the implied warranty of
13
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
14
General Public License for more details.
15
 
16
You should have received a copy of the GNU General Public License
17
along with GNU Classpath; see the file COPYING.  If not, write to the
18
Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
19
02110-1301 USA.
20
 
21
Linking this library statically or dynamically with other modules is
22
making a combined work based on this library.  Thus, the terms and
23
conditions of the GNU General Public License cover the whole
24
combination.
25
 
26
As a special exception, the copyright holders of this library give you
27
permission to link this library with independent modules to produce an
28
executable, regardless of the license terms of these independent
29
modules, and to copy and distribute the resulting executable under
30
terms of your choice, provided that you also meet, for each linked
31
independent module, the terms and conditions of the license of that
32
module.  An independent module is a module which is not derived from
33
or based on this library.  If you modify this library, you may extend
34
this exception to your version of the library, but you are not
35
obligated to do so.  If you do not wish to do so, delete this
36
exception statement from your version. */
37
 
38
 
39
package gnu.java.net;
40
 
41
import gnu.classpath.Configuration;
42
 
43
import java.io.IOException;
44
import java.net.DatagramPacket;
45
import java.net.InetAddress;
46
import java.net.NetworkInterface;
47
import java.net.SocketAddress;
48
import java.net.SocketException;
49
 
50
/**
51
 * The VM interface for {@link gnu.java.net.PlainDatagramSocketImpl}.
52
 *
53
 * @author Ingo Proetel (proetel@aicas.com)
54
 * @author Roman Kennke (kennke@aicas.com)
55
 */
56
public final class VMPlainDatagramSocketImpl
57
{
58
  /**
59
   * Option id for the IP_TTL (time to live) value.
60
   */
61
  static final int IP_TTL = 0x1E61; // 7777
62
 
63
 
64
  // Static initializer to load native library
65
  static
66
  {
67
    if (Configuration.INIT_LOAD_LIBRARY)
68
      {
69
        System.loadLibrary("javanet");
70
      }
71
  }
72
 
73
  /**
74
   * Binds this socket to a particular port and interface
75
   *
76
   * @param socket the socket object
77
   * @param port the port to bind to
78
   * @param addr the address to bind to
79
   *
80
   * @throws SocketException If an error occurs
81
   */
82
  static native void bind(PlainDatagramSocketImpl socket, int port,
83
                          InetAddress addr)
84
    throws SocketException;
85
 
86
  /**
87
   * Creates a new datagram socket.
88
   *
89
   * @param socket the socket object
90
   *
91
   * @throws SocketException If an error occurs
92
   */
93
  static native void create(PlainDatagramSocketImpl socket)
94
    throws SocketException;
95
 
96
  /**
97
   * Connects to the remote address and port specified as arguments.
98
   *
99
   * @param socket the socket object
100
   * @param addr the remote address to connect to
101
   * @param port the remote port to connect to
102
   *
103
   * @throws SocketException If an error occurs
104
   */
105
  static native void connect(PlainDatagramSocketImpl socket, InetAddress addr,
106
                             int port)
107
    throws SocketException;
108
 
109
  /**
110
   * Sends a packet of data to a remote host.
111
   *
112
   * @param socket the socket object
113
   * @param packet the packet to send
114
   *
115
   * @throws IOException If an error occurs
116
   */
117
  static void send(PlainDatagramSocketImpl socket, DatagramPacket packet)
118
    throws IOException
119
  {
120
    nativeSendTo(socket, packet.getAddress(), packet.getPort(),
121
                 packet.getData(), packet.getOffset(), packet.getLength());
122
  }
123
 
124
 
125
  /**
126
   * Sends a packet of data to a remote host.
127
   *
128
   * @param socket the socket object
129
   * @param addr the address to send to
130
   * @param port the port to send to
131
   * @param buf the buffer to send
132
   * @param offset the offset of the data in the buffer to send
133
   * @param len the length of the data to send
134
   *
135
   * @throws IOException If an error occurs
136
   */
137
  private static native void nativeSendTo(PlainDatagramSocketImpl socket,
138
                                          InetAddress addr, int port,
139
                                          byte[] buf, int offset, int len)
140
    throws IOException;
141
 
142
  /**
143
   * Receives a UDP packet from the network
144
   *
145
   * @param socket the socket object
146
   * @param packet the packet to fill in with the data received
147
   *
148
   * @throws IOException IOException If an error occurs
149
   */
150
  static void receive(PlainDatagramSocketImpl socket, DatagramPacket packet)
151
    throws IOException
152
  {
153
    byte[] receiveFromAddress = new byte[4];
154
    int[] receiveFromPort = new int[1];
155
    int[] receivedLength = new int[1];
156
 
157
    nativeReceive(socket, packet.getData(), packet.getOffset(),
158
                  packet.getLength(),
159
                  receiveFromAddress, receiveFromPort, receivedLength);
160
 
161
    packet.setAddress(InetAddress.getByAddress(receiveFromAddress));
162
    packet.setPort(receiveFromPort[0]);
163
    packet.setLength(receivedLength[0]);
164
  }
165
 
166
  private static native void nativeReceive(PlainDatagramSocketImpl socket,
167
                                           byte[] buf, int offset, int len,
168
                                           byte[] receiveFromAddress,
169
                                           int[] receiveFromPort,
170
                                           int[] receivedLength)
171
    throws IOException;
172
 
173
  /**
174
   * Sets the value of an option on the socket
175
   *
176
   * @param socket the socket object
177
   * @param optionId the identifier of the option to set
178
   * @param value the value of the option to set
179
   *
180
   * @exception SocketException If an error occurs
181
   */
182
  static native void setOption(PlainDatagramSocketImpl socket, int optionId,
183
                               Object value)
184
    throws SocketException;
185
 
186
  /**
187
   * Retrieves the value of an option on the socket.
188
   *
189
   * @param socket the socket object
190
   * @param optionId the identifier of the option to retrieve
191
   *
192
   * @return the value of the option
193
   *
194
   * @throws SocketException if an error occurs
195
   */
196
  static native Object getOption(PlainDatagramSocketImpl socket, int optionId)
197
    throws SocketException;
198
 
199
  /**
200
   * Closes the socket.
201
   *
202
   * @param socket the socket object
203
   */
204
  static native void close(PlainDatagramSocketImpl socket);
205
 
206
  /**
207
   * Joins a multicast group
208
   *
209
   * @param addr The group to join
210
   *
211
   * @exception IOException If an error occurs
212
   */
213
  static native void join(PlainDatagramSocketImpl socket, InetAddress addr)
214
    throws IOException;
215
 
216
  /**
217
   * Leaves a multicast group
218
   *
219
   * @param addr The group to leave
220
   *
221
   * @exception IOException If an error occurs
222
   */
223
  static native void leave(PlainDatagramSocketImpl socket, InetAddress addr)
224
    throws IOException;
225
 
226
  /**
227
   * Joins a multicast group.
228
   *
229
   * @param socket the socket object
230
   * @param address the socket address
231
   * @param netIf the network interface
232
   *
233
   * @throws IOException if I/O errors occur
234
   */
235
  static void joinGroup(PlainDatagramSocketImpl socket, SocketAddress address,
236
                        NetworkInterface netIf)
237
    throws IOException
238
  {
239
    throw new InternalError
240
      ("PlainDatagramSocketImpl::joinGroup is not implemented");
241
  }
242
 
243
  /**
244
   * Leaves a multicast group.
245
   *
246
   * @param socket the socket object
247
   * @param address the socket address
248
   * @param netIf the network interface
249
   *
250
   * @throws IOException if I/O errors occur
251
   */
252
  static void leaveGroup(PlainDatagramSocketImpl socket, SocketAddress address,
253
                         NetworkInterface netIf)
254
    throws IOException
255
  {
256
    throw new InternalError
257
      ("PlainDatagramSocketImpl::leaveGroup is not implemented");
258
  }
259
 
260
}

powered by: WebSVN 2.1.0

© copyright 1999-2024 OpenCores.org, equivalent to Oliscience, all rights reserved. OpenCores®, registered trademark.