KNIEXPORT KNI_RETURNTYPE_VOID Java_com_sun_cldc_io_j2me_socket_Protocol_close0() { void *handle = (void*)KNI_GetParameterAsInt(1); void *context; int status = pcsl_socket_close_start(handle, &context); if (status == PCSL_NET_WOULDBLOCK) { do { status = pcsl_socket_close_finish(handle, context); } while (status == PCSL_NET_WOULDBLOCK); } }
/** * Releases any native resources used by the socket connection. * <p> * Java declaration: * <pre> * finalize(V)V * </pre> */ KNIEXPORT KNI_RETURNTYPE_VOID Java_com_sun_midp_io_j2me_socket_Protocol_finalize(void) { void *pcslHandle; int status = PCSL_NET_INVALID; void* context = NULL; KNI_StartHandles(1); KNI_DeclareHandle(thisObject); KNI_GetThisPointer(thisObject); pcslHandle = (void *)(getMidpSocketProtocolPtr(thisObject)->handle); REPORT_INFO1(LC_PROTOCOL, "socket::finalize handle=%d\n", pcslHandle); if (INVALID_HANDLE != pcslHandle) { status = pcsl_socket_close_start(pcslHandle, &context); getMidpSocketProtocolPtr(thisObject)->handle = (jint)INVALID_HANDLE; if (midpDecResourceCount(RSC_TYPE_TCP_CLI, 1) == 0) { REPORT_INFO(LC_PROTOCOL, "Resource limit update error"); } if (status == PCSL_NET_IOERROR) { midp_snprintf(gKNIBuffer, KNI_BUFFER_SIZE, "IOError in socket::finalize error=%d\n", (int)pcsl_network_error(pcslHandle)); REPORT_ERROR1(LC_PROTOCOL, "%s", gKNIBuffer); } else if (status == PCSL_NET_WOULDBLOCK) { /* blocking during finalize is not supported */ REPORT_CRIT1(LC_PROTOCOL, "socket::finalize = 0x%x blocked\n", pcslHandle); } } FINISH_NETWORK_INDICATOR; KNI_EndHandles(); KNI_ReturnVoid(); }
/** * Internal utility to close a socket synchronously. * * @param handle the socket to close * * @return 1 if successful, 0 if failure */ static int utilClose(void *handle) { int status; void *context; status = pcsl_socket_close_start(handle, &context); if (status == PCSL_NET_SUCCESS) { return 1; } if (status == PCSL_NET_WOULDBLOCK) { if (wait_on_handle(handle, 1)) { status = pcsl_socket_close_finish(handle, context); if (status == PCSL_NET_SUCCESS) { return 1; } } } return 0; }
/** * See pcsl_serversocket.h for definition. */ int pcsl_sereversocket_close_start( void *handle, void **pContext) { return pcsl_socket_close_start(handle, pContext); }
void testClose(void *handle) { status = pcsl_socket_close_start(handle, &pContext); assertTrue("Error in closing socket connection", status == PCSL_NET_SUCCESS); }
/** * Closes the socket connection. * <p> * Java declaration: * <pre> * close0(V)V * </pre> */ KNIEXPORT KNI_RETURNTYPE_VOID Java_com_sun_midp_io_j2me_socket_Protocol_close0(void) { void *pcslHandle; int status = PCSL_NET_INVALID; void* context = NULL; MidpReentryData* info; KNI_StartHandles(1); KNI_DeclareHandle(thisObject); KNI_GetThisPointer(thisObject); info = (MidpReentryData*)SNI_GetReentryData(NULL); if (info == NULL) { /* initial invocation */ pcslHandle = (void *)(getMidpSocketProtocolPtr(thisObject)->handle); if (INVALID_HANDLE == pcslHandle) { KNI_ThrowNew(midpIOException, "invalid handle during socket::close"); } else { status = pcsl_socket_close_start(pcslHandle, &context); getMidpSocketProtocolPtr(thisObject)->handle = (jint)INVALID_HANDLE; midp_thread_signal(NETWORK_READ_SIGNAL, (int)pcslHandle, 0); midp_thread_signal(NETWORK_WRITE_SIGNAL, (int)pcslHandle, 0); } } else { /* reinvocation */ pcslHandle = (void *)(info->descriptor); context = info->pResult; status = pcsl_socket_close_finish(pcslHandle, context); } REPORT_INFO1(LC_PROTOCOL, "socket::close handle=%d\n", pcslHandle); if (INVALID_HANDLE != pcslHandle) { if (status == PCSL_NET_SUCCESS) { if (midpDecResourceCount(RSC_TYPE_TCP_CLI, 1) == 0) { REPORT_INFO(LC_PROTOCOL, "Resource limit update error"); } } else if (status == PCSL_NET_WOULDBLOCK) { REPORT_INFO1(LC_PROTOCOL, "socket::close = 0x%x blocked\n", pcslHandle); /* IMPL NOTE: unclear whether this is the right signal */ midp_thread_wait(NETWORK_READ_SIGNAL, (int)pcslHandle, context); } else { /* must be PCSL_NET_IOERROR */ midp_snprintf(gKNIBuffer, KNI_BUFFER_SIZE, "IOError in socket::close = %d\n", (int)pcsl_network_error(pcslHandle)); REPORT_INFO1(LC_PROTOCOL, "%s", gKNIBuffer); KNI_ThrowNew(midpIOException, gKNIBuffer); } } KNI_EndHandles(); KNI_ReturnVoid(); }