int testAvailable(void *handle) { int numBytes; usleep(200); status = pcsl_socket_available(handle, &numBytes); assertTrue("Error in available() at socket ", status == PCSL_NET_SUCCESS); return numBytes; }
/** * Test retrieval of the number of bytes available. */ void testAvailable() { int status; void *handle; int avail; int ii; status = utilOpen(&handle, testaddr, PORT_CHARGEN); assertTrue("open failed", status); wait_on_handle(handle, 1); for (ii = 0; ii < 5; ii++) { status = pcsl_socket_available(handle, &avail); assertTrue("available failed", status == PCSL_NET_SUCCESS); printf("avail = %d\n", avail); usleep(1000); } (void)utilClose(handle); }
/** * Gets the number of bytes that can be read without blocking. * <p> * Java declaration: * <pre> * available0(V)I * </pre> * * @return number of bytes that can be read without blocking */ KNIEXPORT KNI_RETURNTYPE_INT Java_com_sun_midp_io_j2me_socket_Protocol_available0(void) { void *pcslHandle; int bytesAvailable = 0; KNI_StartHandles(1); KNI_DeclareHandle(thisObject); KNI_GetThisPointer(thisObject); pcslHandle = (void *)(getMidpSocketProtocolPtr(thisObject)->handle); KNI_EndHandles(); REPORT_INFO1(LC_PROTOCOL, "socket::available0 fd=%d\n", (int)pcslHandle); if (INVALID_HANDLE == pcslHandle) { KNI_ThrowNew(midpIOException, "invalid handle during socket::available"); } else { int status; status = pcsl_socket_available(pcslHandle, &bytesAvailable); /* status is only PCSL_NET_SUCCESS or PCSL_NET_IOERROR */ if (status == PCSL_NET_IOERROR) { bytesAvailable = 0; midp_snprintf(gKNIBuffer, KNI_BUFFER_SIZE, "IOError %d during socket::available0", pcsl_network_error(pcslHandle)); KNI_ThrowNew(midpIOException, gKNIBuffer); } } REPORT_INFO1(LC_PROTOCOL, "socket::available0 bytesAvailable=%d\n", bytesAvailable); KNI_ReturnInt((jint)bytesAvailable); }
static int do_pcsl_available(void *handle,int *pBytesAvailable) { return pcsl_socket_available(handle,pBytesAvailable); }