#include <cutils/properties.h>
#include <cutils/adb_networking.h>
-#include <utils/LogSocket.h>
#include "AndroidSystemNatives.h"
// Temporary hack to build on systems that don't have up-to-date libc headers.
}
/**
- * Wrapper function for log_socket_connect, which is currently disabled.
- * TODO: either unbreak log_socket_connect and fix it to take strings or IP
- * addresses or remove it. After that, remove this function.
- *
- * @param fd the socket file descriptor to enable logging on
- * @param address pointer to the socket address the socket is connecting to
- */
-static void logSocketConnect(int fd, struct sockaddr_storage *address) {
- // Since connection logging is disabled for now, don't implement IPv6
- // support for it just yet.
- if (address->ss_family == AF_INET) {
- struct sockaddr_in *sin = (struct sockaddr_in *) address;
- log_socket_connect(fd, ntohl(sin->sin_addr.s_addr),
- ntohs(sin->sin_port));
- }
-}
-
-/**
* Returns the port number in a sockaddr_storage structure.
*
* @param address the sockaddr_storage structure to get the port from
}
} else if (0 > result) {
- log_socket_close(handle, result);
throwSocketException(env, result);
}
poll = 0;
continue; // try again
} else if (0 > result) {
- log_socket_close(handle, result);
throwSocketException(env, result);
}
poll = 0;
// LOGD("-connect ret %d errno %d (via adb)", rc, errno);
} else {
- logSocketConnect(handle, &addr);
-
/* set the socket to non-blocking */
int block = JNI_TRUE;
rc = ioctl(handle, FIONBIO, &block);
return -1;
} else if (ret == -1) {
int err = convertError(errno);
- log_socket_close(handle, err);
throwSocketException(env, err);
return 0;
}
- add_recv_stats(handle, ret);
return ret;
}
result = send(handle, (jbyte *) message, (int) count, SOCKET_NOFLAGS);
if (result < 0) {
int err = convertError(errno);
- log_socket_close(handle, err);
if (SOCKERR_WOULDBLOCK == err){
jclass socketExClass,errorCodeExClass;
return 0;
}
- add_send_stats(handle, result);
return result;
}
sockConnectWithTimeout(handle, address, 0, SOCKET_STEP_DONE, context);
goto bail;
} else if (result != SOCKERR_NOTCONNECTED) {
- log_socket_close(handle, result);
sockConnectWithTimeout(handle, address, 0, SOCKET_STEP_DONE,
context);
/* we got an error other than NOTCONNECTED so we cannot continue */
if (hasTimeout) {
remainingTimeout = finishTime - time_msec_clock();
if (remainingTimeout <= 0) {
- log_socket_close(handle, result);
sockConnectWithTimeout(handle, address, 0,
SOCKET_STEP_DONE, context);
jniThrowException(env,
remainingTimeout = 100;
}
} else {
- log_socket_close(handle, result);
sockConnectWithTimeout(handle, address, remainingTimeout,
SOCKET_STEP_DONE, context);
if ((SOCKERR_CONNRESET == result) ||
if (ret < 0) {
int err = convertError(errno);
- log_socket_close(handle, err);
throwSocketException(env, err);
return;
}
} else if (SOCKERR_INTERRUPTED == result) {
continue;
} else if (0 > result) {
- log_socket_close(handle, result);
throwSocketException(env, result);
return 0;
}
if (0 > result) {
int err = convertError(errno);
- log_socket_close(handle, err);
throwSocketException(env, err);
return 0;
}
- add_recv_stats(handle, result);
return result;
}
if (ret < 0) {
int err = convertError(errno);
- log_socket_close(handle, err);
throwSocketException(env, err);
return;
}
result = send(handle, (jbyte *) &value, 1, MSG_OOB);
if (result < 0) {
int err = convertError(errno);
- log_socket_close(handle, err);
throwSocketException(env, err);
}
}
if (ret < 0) // Exception has already been thrown.
return;
- logSocketConnect(handle, &sockAddr);
-
do {
ret = connect(handle, (struct sockaddr *) &sockAddr, sizeof(sockAddr));
} while (ret < 0 && errno == EINTR);
if (ret < 0) {
int err = convertError(errno);
- log_socket_close(handle, err);
throwSocketException(env, err);
}
}
} while (result < 0 && errno == EINTR);
if (result < 0) {
int err = convertError(errno);
- log_socket_close(handle, err);
throwSocketException(env, err);
}
}
} while (ret < 0 && errno == EINTR);
if (ret < 0) {
int err = convertError(errno);
- log_socket_close(handle, err);
jniThrowException(env, "java/net/BindException", netLookupErrorString(err));
return 0;
}
} while (length < 0 && errno == EINTR);
if (length < 0) {
int err = convertError(errno);
- log_socket_close(handle, err);
throwSocketException(env, err);
return 0;
}
return -1;
port = getSocketAddressPort(&sockAddr);
- add_recv_stats(handle, length);
return port;
}
} while (actualLength < 0 && errno == EINTR);
if (actualLength < 0) {
int err = convertError(errno);
- log_socket_close(handle, err);
throwSocketException(env, err);
return 0;
}
env->SetIntField(packet, gCachedFields.dpack_length,
(jint) actualLength);
}
- add_recv_stats(handle, actualLength);
return (jint) actualLength;
}
if ( packet != NULL) {
env->SetIntField(packet, gCachedFields.dpack_length, actualLength);
}
- add_recv_stats(handle, actualLength);
return actualLength;
}
|| (SOCKERR_CONNECTION_REFUSED == err)) {
return 0;
} else {
- log_socket_close(handle, err);
throwSocketException(env, err);
return 0;
}
}
- add_send_stats(handle, result);
return (jint) result;
}
if ((SOCKERR_CONNRESET == err) || (SOCKERR_CONNECTION_REFUSED == err)) {
return 0;
} else {
- log_socket_close(handle, err);
throwSocketException(env, err);
return 0;
}
}
- add_send_stats(handle, length);
return result;
}
* to the Java input stream
*/
if (0 < result) {
- add_recv_stats(handle, result);
return result;
} else if (0 == result) {
return -1;
netLookupErrorString(SOCKERR_TIMEOUT));
} else {
int err = convertError(errno);
- log_socket_close(handle, err);
throwSocketException(env, err);
}
return 0;
}
env->ReleaseByteArrayElements(data, message, 0);
int err = convertError(result);
- log_socket_close(handle, err);
throwSocketException(env, err);
return 0;
}
}
env->ReleaseByteArrayElements(data, message, 0);
- add_send_stats(handle, sent);
return sent;
}
if (ret < 0) {
int err = convertError(errno);
- log_socket_close(handle, err);
throwSocketException(env, err);
return;
}
if (ret < 0) {
int err = convertError(errno);
- log_socket_close(handle, err);
throwSocketException(env, err);
return;
}
} while (result < 0 && errno == EINTR);
if (result < 0) {
int err = convertError(errno);
- log_socket_close(handle, err);
throwSocketException(env, err);
free(message);
return 0;
}
free(message);
- add_send_stats(handle, sent);
return sent;
}
return;
}
- log_socket_close(handle, SOCKET_CLOSE_LOCAL);
-
jniSetFileDescriptorOfFD(env, fileDescriptor, -1);
close(handle);