source: trunk/gcc/libjava/gnu/java/nio/natSocketChannelImpl.cc

Last change on this file was 1389, checked in by bird, 21 years ago

Initial revision

  • Property cvs2svn:cvs-rev set to 1.1
  • Property svn:eol-style set to native
  • Property svn:executable set to *
File size: 4.6 KB
Line 
1// natSocketChannelImpl.cc
2
3/* Copyright (C) 2002, 2003 Free Software Foundation
4
5 This file is part of libgcj.
6
7This software is copyrighted work licensed under the terms of the
8Libgcj License. Please consult the file "LIBGCJ_LICENSE" for
9details. */
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
25jint
26gnu::java::nio::SocketChannelImpl::SocketCreate ()
27{
28 throw new ::java::io::IOException (JvNewStringUTF ("SocketCreate not implemented"));
29}
30
31jint
32gnu::java::nio::SocketChannelImpl::SocketConnect (jint,
33 ::java::net::InetAddress *,
34 jint)
35{
36 throw new ::java::io::IOException (JvNewStringUTF ("SocketConnect not implemented"));
37}
38
39jint
40gnu::java::nio::SocketChannelImpl::SocketBind (jint, ::java::net::InetAddress *,
41 jint)
42{
43 throw new ::java::io::IOException (JvNewStringUTF ("SocketBind not implemented"));
44}
45
46jint
47gnu::java::nio::SocketChannelImpl::SocketListen (jint, jint)
48{
49 throw new ::java::io::IOException (JvNewStringUTF ("SocketList not implemented"));
50}
51
52jint
53gnu::java::nio::SocketChannelImpl::SocketAvailable (jint)
54{
55 throw new ::java::net::SocketException (JvNewStringLatin1 ("SocketAvailable: not implemented"));
56}
57
58jint
59gnu::java::nio::SocketChannelImpl::SocketClose (jint)
60{
61 throw new ::java::net::SocketException (JvNewStringLatin1 ("SocketClose: not implemented"));
62}
63
64jint
65gnu::java::nio::SocketChannelImpl::SocketRead (jint, jbyteArray, jint, jint)
66{
67 throw new ::java::net::SocketException (JvNewStringLatin1 ("SocketRead: not implemented"));
68}
69
70jint
71gnu::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
78jint
79gnu::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
92jint
93gnu::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
100jint
101gnu::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
108jint
109gnu::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
122jint
123gnu::java::nio::SocketChannelImpl::SocketAvailable (jint /*fd*/)
124{
125 throw new ::java::net::SocketException (JvNewStringLatin1 ("SocketAvailable: not implemented"));
126}
127
128jint
129gnu::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
142jint
143gnu::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
159jint
160gnu::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
Note: See TracBrowser for help on using the repository browser.