+/*
+ * Class: com/sun/cldc/io/j2me/socket/Protocol
+ * Method: readByte
+ * Signature: (I)I
+ */
+JNIEXPORT s4 JNICALL Java_com_sun_cldc_io_j2me_socket_Protocol_readByte(JNIEnv *env, jclass clazz, s4 handle) {
+
+ char byte;
+ ssize_t result;
+
+ /* receive from the socket */
+
+ result = recv(handle, &byte, 1, 0);
+
+ if (result == 0) {
+ /* the peer has performed an orderly shutdown */
+
+ return -1;
+ }
+ else if (result < 0) {
+ /* should throw an IOException */
+
+ vm_abort("Java_com_sun_cldc_io_j2me_socket_Protocol_readByte: recv failed: %s", strerror(errno));
+ }
+
+ return byte;
+}
+
+
+/*
+ * Class: com/sun/cldc/io/j2me/socket/Protocol
+ * Method: writeBuf
+ * Signature: (I[BII)I
+ */
+JNIEXPORT s4 JNICALL Java_com_sun_cldc_io_j2me_socket_Protocol_writeBuf(JNIEnv *env, jclass clazz, s4 handle, java_bytearray* b, s4 off, s4 len) {
+
+ void *buf;
+ ssize_t result;
+
+ /* get pointer to the buffer */
+
+ buf = &(b->data[off]);
+
+ /* send the given byte to the socket */
+
+ result = send(handle, buf, len, 0);
+
+ if (result < 0)
+ /* should throw an IOException */
+
+ vm_abort("Java_com_sun_cldc_io_j2me_socket_Protocol_writeBuf: send failed: %s", strerror(errno));
+
+ return result;
+
+}
+
+