1 | // natSocketChannelImpl.cc
|
---|
2 |
|
---|
3 | /* Copyright (C) 2002, 2003 Free Software Foundation
|
---|
4 |
|
---|
5 | This file is part of libgcj.
|
---|
6 |
|
---|
7 | This software is copyrighted work licensed under the terms of the
|
---|
8 | Libgcj License. Please consult the file "LIBGCJ_LICENSE" for
|
---|
9 | details. */
|
---|
10 |
|
---|
11 | #include <config.h>
|
---|
12 | #include <platform.h>
|
---|
13 |
|
---|
14 | #include <errno.h>
|
---|
15 |
|
---|
16 | #include <gcj/cni.h>
|
---|
17 | #include <gnu/java/nio/SocketChannelImpl.h>
|
---|
18 | #include <java/io/IOException.h>
|
---|
19 | #include <java/net/InetAddress.h>
|
---|
20 | #include <java/net/SocketException.h>
|
---|
21 |
|
---|
22 |
|
---|
23 | #ifdef DISABLE_JAVA_NET
|
---|
24 |
|
---|
25 | jint
|
---|
26 | gnu::java::nio::SocketChannelImpl::SocketCreate ()
|
---|
27 | {
|
---|
28 | throw new ::java::io::IOException (JvNewStringUTF ("SocketCreate not implemented"));
|
---|
29 | }
|
---|
30 |
|
---|
31 | jint
|
---|
32 | gnu::java::nio::SocketChannelImpl::SocketConnect (jint,
|
---|
33 | ::java::net::InetAddress *,
|
---|
34 | jint)
|
---|
35 | {
|
---|
36 | throw new ::java::io::IOException (JvNewStringUTF ("SocketConnect not implemented"));
|
---|
37 | }
|
---|
38 |
|
---|
39 | jint
|
---|
40 | gnu::java::nio::SocketChannelImpl::SocketBind (jint, ::java::net::InetAddress *,
|
---|
41 | jint)
|
---|
42 | {
|
---|
43 | throw new ::java::io::IOException (JvNewStringUTF ("SocketBind not implemented"));
|
---|
44 | }
|
---|
45 |
|
---|
46 | jint
|
---|
47 | gnu::java::nio::SocketChannelImpl::SocketListen (jint, jint)
|
---|
48 | {
|
---|
49 | throw new ::java::io::IOException (JvNewStringUTF ("SocketList not implemented"));
|
---|
50 | }
|
---|
51 |
|
---|
52 | jint
|
---|
53 | gnu::java::nio::SocketChannelImpl::SocketAvailable (jint)
|
---|
54 | {
|
---|
55 | throw new ::java::net::SocketException (JvNewStringLatin1 ("SocketAvailable: not implemented"));
|
---|
56 | }
|
---|
57 |
|
---|
58 | jint
|
---|
59 | gnu::java::nio::SocketChannelImpl::SocketClose (jint)
|
---|
60 | {
|
---|
61 | throw new ::java::net::SocketException (JvNewStringLatin1 ("SocketClose: not implemented"));
|
---|
62 | }
|
---|
63 |
|
---|
64 | jint
|
---|
65 | gnu::java::nio::SocketChannelImpl::SocketRead (jint, jbyteArray, jint, jint)
|
---|
66 | {
|
---|
67 | throw new ::java::net::SocketException (JvNewStringLatin1 ("SocketRead: not implemented"));
|
---|
68 | }
|
---|
69 |
|
---|
70 | jint
|
---|
71 | gnu::java::nio::SocketChannelImpl::SocketWrite (jint, jbyteArray, jint, jint)
|
---|
72 | {
|
---|
73 | throw new ::java::net::SocketException (JvNewStringLatin1 ("SocketWrite: not implemented"));
|
---|
74 | }
|
---|
75 |
|
---|
76 | #else // DISABLE_JAVA_NET
|
---|
77 |
|
---|
78 | jint
|
---|
79 | gnu::java::nio::SocketChannelImpl::SocketCreate ()
|
---|
80 | {
|
---|
81 | int sock = _Jv_socket (AF_INET, SOCK_STREAM, 0);
|
---|
82 |
|
---|
83 | if (sock < 0)
|
---|
84 | {
|
---|
85 | char* strerr = strerror (errno);
|
---|
86 | throw new ::java::io::IOException (JvNewStringUTF (strerr));
|
---|
87 | }
|
---|
88 |
|
---|
89 | return sock;
|
---|
90 | }
|
---|
91 |
|
---|
92 | jint
|
---|
93 | gnu::java::nio::SocketChannelImpl::SocketConnect (jint fd,
|
---|
94 | ::java::net::InetAddress *addr,
|
---|
95 | jint port)
|
---|
96 | {
|
---|
97 | throw new ::java::io::IOException (JvNewStringUTF ("SocketConnect not implemented"));
|
---|
98 | }
|
---|
99 |
|
---|
100 | jint
|
---|
101 | gnu::java::nio::SocketChannelImpl::SocketBind (jint fd,
|
---|
102 | ::java::net::InetAddress *addr,
|
---|
103 | jint port)
|
---|
104 | {
|
---|
105 | throw new ::java::io::IOException (JvNewStringUTF ("SocketBind not implemented"));
|
---|
106 | }
|
---|
107 |
|
---|
108 | jint
|
---|
109 | gnu::java::nio::SocketChannelImpl::SocketListen (jint fd, jint backlog)
|
---|
110 | {
|
---|
111 | int result = _Jv_listen (fd, backlog);
|
---|
112 |
|
---|
113 | if (result < 0)
|
---|
114 | {
|
---|
115 | char* strerr = strerror (errno);
|
---|
116 | throw new ::java::io::IOException (JvNewStringUTF (strerr));
|
---|
117 | }
|
---|
118 |
|
---|
119 | return result;
|
---|
120 | }
|
---|
121 |
|
---|
122 | jint
|
---|
123 | gnu::java::nio::SocketChannelImpl::SocketAvailable (jint /*fd*/)
|
---|
124 | {
|
---|
125 | throw new ::java::net::SocketException (JvNewStringLatin1 ("SocketAvailable: not implemented"));
|
---|
126 | }
|
---|
127 |
|
---|
128 | jint
|
---|
129 | gnu::java::nio::SocketChannelImpl::SocketClose (jint fd)
|
---|
130 | {
|
---|
131 | int result = _Jv_close (fd);
|
---|
132 |
|
---|
133 | if (result < 0)
|
---|
134 | {
|
---|
135 | char* strerr = strerror (errno);
|
---|
136 | throw new ::java::io::IOException (JvNewStringUTF (strerr));
|
---|
137 | }
|
---|
138 |
|
---|
139 | return result;
|
---|
140 | }
|
---|
141 |
|
---|
142 | jint
|
---|
143 | gnu::java::nio::SocketChannelImpl::SocketRead (jint fd, jbyteArray data,
|
---|
144 | jint offset, jint length)
|
---|
145 | {
|
---|
146 | /* The cast to char* is needed to placate the Win32 API. */
|
---|
147 | int result =
|
---|
148 | ::recv (fd, reinterpret_cast<char*>(elements(data)), offset, length);
|
---|
149 |
|
---|
150 | if (result < 0)
|
---|
151 | {
|
---|
152 | char* strerr = strerror (errno);
|
---|
153 | throw new ::java::io::IOException (JvNewStringUTF (strerr));
|
---|
154 | }
|
---|
155 |
|
---|
156 | return result;
|
---|
157 | }
|
---|
158 |
|
---|
159 | jint
|
---|
160 | gnu::java::nio::SocketChannelImpl::SocketWrite (jint fd, jbyteArray data,
|
---|
161 | jint offset, jint length)
|
---|
162 | {
|
---|
163 | /* The cast to char* is needed to placate the Win32 API. I used char*
|
---|
164 | instead of const char* because I wasn't sure about the API on all
|
---|
165 | UNICES. */
|
---|
166 | int result =
|
---|
167 | ::send (fd, reinterpret_cast<char*>(elements(data)), offset, length);
|
---|
168 |
|
---|
169 | if (result < 0)
|
---|
170 | {
|
---|
171 | char* strerr = strerror (errno);
|
---|
172 | throw new ::java::io::IOException (JvNewStringUTF (strerr));
|
---|
173 | }
|
---|
174 |
|
---|
175 | return result;
|
---|
176 | }
|
---|
177 |
|
---|
178 | #endif // DISABLE_JAVA_NET
|
---|