1 |
/* PlainSocketImpl.c - Native methods for PlainSocketImpl class |
/* PlainSocketImpl.c - Native methods for PlainSocketImpl class |
2 |
Copyright (C) 1998 Free Software Foundation, Inc. |
Copyright (C) 1998, 2002 Free Software Foundation, Inc. |
3 |
|
|
4 |
This file is part of GNU Classpath. |
This file is part of GNU Classpath. |
5 |
|
|
36 |
exception statement from your version. */ |
exception statement from your version. */ |
37 |
|
|
38 |
|
|
39 |
|
#include <errno.h> |
40 |
|
#include <sys/ioctl.h> |
41 |
|
#include <asm/ioctls.h> |
42 |
|
#include <string.h> |
43 |
|
|
44 |
#include <jni.h> |
#include <jni.h> |
45 |
|
#include <jcl.h> |
46 |
|
|
47 |
#include "java_net_PlainSocketImpl.h" |
#include "java_net_PlainSocketImpl.h" |
48 |
|
|
129 |
} |
} |
130 |
|
|
131 |
/*************************************************************************/ |
/*************************************************************************/ |
132 |
|
|
133 |
|
JNIEXPORT jint JNICALL |
134 |
|
Java_java_net_PlainSocketImpl_available(JNIEnv *env, jobject this) |
135 |
|
{ |
136 |
|
int fd; |
137 |
|
int count = 0; |
138 |
|
jclass cls; |
139 |
|
jfieldID fid; |
140 |
|
|
141 |
|
cls = (*env)->GetObjectClass(env, this); |
142 |
|
if (cls == 0) |
143 |
|
{ |
144 |
|
JCL_ThrowException(env, IO_EXCEPTION, "internal error"); |
145 |
|
return 0; |
146 |
|
} |
147 |
|
|
148 |
|
fid = (*env)->GetFieldID(env, cls, "native_fd", "I"); |
149 |
|
if (fid == 0) |
150 |
|
{ |
151 |
|
JCL_ThrowException(env, IO_EXCEPTION, "internal error"); |
152 |
|
return 0; |
153 |
|
} |
154 |
|
|
155 |
|
fd = (*env)->GetIntField(env, this, fid); |
156 |
|
|
157 |
|
if (ioctl(fd, FIONREAD, &count) == -1) |
158 |
|
{ |
159 |
|
JCL_ThrowException(env, IO_EXCEPTION, strerror(errno)); |
160 |
|
return 0; |
161 |
|
} |
162 |
|
else |
163 |
|
return count; |
164 |
|
} |
165 |
|
|
166 |
|
/*************************************************************************/ |
167 |
|
|
168 |
/* |
/* |
169 |
* This method sets the specified option for a socket |
* This method sets the specified option for a socket |