1 /* src/native/vm/cldc1.1/com_sun_cldc_io_j2me_socket_Protocol.c
3 Copyright (C) 2007 R. Grafl, A. Krall, C. Kruegel, C. Oates,
4 R. Obermaisser, M. Platter, M. Probst, S. Ring, E. Steiner,
5 C. Thalinger, D. Thuernbeck, P. Tomsich, C. Ullrich, J. Wenninger,
6 Institut f. Computersprachen - TU Wien
8 This file is part of CACAO.
10 This program is free software; you can redistribute it and/or
11 modify it under the terms of the GNU General Public License as
12 published by the Free Software Foundation; either version 2, or (at
13 your option) any later version.
15 This program is distributed in the hope that it will be useful, but
16 WITHOUT ANY WARRANTY; without even the implied warranty of
17 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
18 General Public License for more details.
20 You should have received a copy of the GNU General Public License
21 along with this program; if not, write to the Free Software
22 Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
25 $Id: java_lang_VMRuntime.c 5900 2006-11-04 17:30:44Z michi $
34 #include <sys/types.h>
35 #include <sys/socket.h>
39 #include "mm/memory.h"
41 #include "native/jni.h"
43 #include "vm/global.h"
47 * Class: com/sun/cldc/io/j2me/socket/Protocol
51 JNIEXPORT s4 JNICALL Java_com_sun_cldc_io_j2me_socket_Protocol_open0(JNIEnv *env, jclass clazz, java_bytearray *hostname, s4 port, s4 mode)
53 struct hostent *phostent;
54 struct sockaddr_in serv_addr;
59 /* The hostname byte-array is a NULL terminated C-string. */
61 name = (char *) &(hostname->data);
65 phostent = gethostbyname(name);
70 /* fill the sockaddr structure */
72 serv_addr.sin_family = AF_INET;
73 serv_addr.sin_port = htons(port);
75 MCOPY(&serv_addr.sin_addr, phostent->h_addr, u1, phostent->h_length);
77 /* create the socket */
79 sockfd = socket(AF_INET, SOCK_STREAM, 0);
84 /* connect the socket */
86 result = connect(sockfd, (struct sockaddr *) &serv_addr, sizeof(serv_addr));
96 * Class: com/sun/cldc/io/j2me/socket/Protocol
100 JNIEXPORT s4 JNICALL Java_com_sun_cldc_io_j2me_socket_Protocol_readBuf(JNIEnv *env, jclass clazz, s4 handle, java_bytearray *b, s4 off, s4 len)
105 /* get pointer to the buffer */
107 buf = &(b->data[off]);
109 /* receive from the socket */
111 result = recv(handle, buf, len, 0);
114 /* the peer has performed an orderly shutdown */
118 else if (result < 0) {
119 vm_abort("Java_com_sun_cldc_io_j2me_socket_Protocol_readBuf: recv failed: %s", strerror(errno));
127 * Class: com/sun/cldc/io/j2me/socket/Protocol
131 JNIEXPORT s4 JNICALL Java_com_sun_cldc_io_j2me_socket_Protocol_writeByte(JNIEnv *env, jclass clazz, s4 handle, s4 b)
138 /* send the given byte to the socket */
140 result = send(handle, &byte, 1, 0);
143 vm_abort("Java_com_sun_cldc_io_j2me_socket_Protocol_writeByte: send failed: %s", strerror(errno));
150 * These are local overrides for various environment variables in Emacs.
151 * Please do not remove this and leave it at the end of the file, where
152 * Emacs will automagically detect them.
153 * ---------------------------------------------------------------------
156 * indent-tabs-mode: t
160 * vim:noexpandtab:sw=4:ts=4: