这篇教程C++ throwIOException函数代码示例写得很实用,希望能帮到您。
本文整理汇总了C++中throwIOException函数的典型用法代码示例。如果您正苦于以下问题:C++ throwIOException函数的具体用法?C++ throwIOException怎么用?C++ throwIOException使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。 在下文中一共展示了throwIOException函数的26个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的C++代码示例。 示例1: getPeerJNIEXPORT jint JNICALL Java_com_codeminders_hidapi_HIDDevice_readTimeout(JNIEnv *env, jobject self, jbyteArray data, jint milliseconds ){ hid_device *peer = getPeer(env, self); if(!peer) { throwIOException(env, peer); return 0; /* not an error, freed previously */ } jsize bufsize = env->GetArrayLength(data); jbyte *buf = env->GetByteArrayElements(data, NULL); int read = hid_read_timeout(peer, (unsigned char*) buf, bufsize, milliseconds); env->ReleaseByteArrayElements(data, buf, read==-1?JNI_ABORT:0); if(read == 0) /* time out */ { return 0; } else if(read == -1) { throwIOException(env, peer); return 0; /* not an error, freed previously */ } return read;}
开发者ID:DeqingSun,项目名称:javahidapi,代码行数:25,
示例2: android_security_cts_LinuxRngTest_getCharDeviceMinorjint android_security_cts_LinuxRngTest_getCharDeviceMinor(JNIEnv* env, jobject thiz, jstring name){ const char* nameStr = env->GetStringUTFChars(name, NULL); jint result = -1; struct stat st; if (stat(nameStr, &st) == -1) { throwIOException(env, "Failed to stat %s: %s", nameStr, strerror(errno)); goto ret; } if (!S_ISCHR(st.st_mode)) { throwIOException(env, "%s is not a character device: mode is 0%o", nameStr, st.st_mode); goto ret; } result = minor(st.st_rdev);ret: if (nameStr != NULL) { env->ReleaseStringUTFChars(name, nameStr); } return result;}
开发者ID:10114395,项目名称:android-5.0.0_r5,代码行数:25,
示例3: FUNCJNIEXPORT jstring FUNC(getPortName)(JNIEnv *env, jclass cls, jint i){ HKEY key; if (RegOpenKeyEx(HKEY_LOCAL_MACHINE, L"HARDWARE//DEVICEMAP//SERIALCOMM", 0, KEY_READ, &key) != ERROR_SUCCESS) { throwIOException(env, "Can not find registry key"); return NULL; } wchar_t name[256]; DWORD len = sizeof(name); LONG rc = RegEnumValue(key, (DWORD)i, name, &len, NULL, NULL, NULL, NULL); if (rc != ERROR_SUCCESS) { if (rc != ERROR_NO_MORE_ITEMS) { throwIOException(env, "Can not enum value"); } RegCloseKey(key); return NULL; } wchar_t value[256]; DWORD type; len = sizeof(value); if (RegQueryValueEx(key, name, NULL, &type, (BYTE *)value, &len) != ERROR_SUCCESS) { throwIOException(env, "Can not query value"); RegCloseKey(key); return NULL; } jstring result = env->NewString((jchar *)value, (jsize) wcslen(value)); RegCloseKey(key); return result;}
开发者ID:MarcMil,项目名称:cdt,代码行数:33,
示例4: sprintf/* * Class: com_pi4j_jni_Serial * Method: echo * Signature: (IZ)V */JNIEXPORT void JNICALL Java_com_pi4j_jni_Serial_echo(JNIEnv *env, jclass obj, jint fd, jboolean enabled){ struct termios options ; // get and modify current options: if(tcgetattr (fd, &options) == -1){ int err_number = errno; char err_message[100]; sprintf(err_message, "Failed to GET terminal attributes for the serial port. (Error #%d)", err_number); throwIOException(env, err_message); } if(enabled == JNI_FALSE){ // disable ECHO options.c_lflag &= ~ECHO; } else{ // enable ECHO options.c_lflag |= ECHO; } // set updated options if(tcsetattr (fd, TCSANOW, &options) == -1){ int err_number = errno; char err_message[100]; sprintf(err_message, "Failed to SET terminal attributes for the serial port. (Error #%d)", err_number); throwIOException(env, err_message); }}
开发者ID:alexmao86,项目名称:pi4j,代码行数:35,
示例5: memsetJNIEXPORT jboolean JNICALL Java_com_intel_bluetooth_BluetoothStackBlueZ_l2Ready (JNIEnv* env, jobject peer, jlong handle) { struct pollfd fds; int timeout = 10; // milliseconds memset(&fds, 0, sizeof(fds)); fds.fd = handle; fds.events = POLLIN | POLLHUP | POLLERR;// | POLLRDHUP; fds.revents = 0; int poll_rc = poll(&fds, 1, timeout); if (poll_rc > 0) { if (fds.revents & (POLLHUP | POLLERR /*| POLLRDHUP*/)) { throwIOException(env, "Peer closed connection"); return JNI_FALSE; } else if (fds.revents & POLLNVAL) { // this connection has been closed by invoking the close() method. throwIOException(env, "Connection closed"); return JNI_FALSE; } else if (fds.revents & POLLIN) { return JNI_TRUE; } } else if (poll_rc == -1) { throwIOException(env, "Failed to read. [%d] %s", errno, strerror(errno)); return JNI_FALSE; } else { //Edebug("poll: call timed out"); } return JNI_FALSE;}
开发者ID:AfonsodelCB,项目名称:bluecove,代码行数:28,
示例6: fprintfJNIEXPORT void JNICALL Java_org_apache_activemq_artemis_jlibaio_LibaioContext_fill (JNIEnv * env, jclass clazz, jint fd, jlong size){ int i; int blocks = size / ONE_MEGA; int rest = size % ONE_MEGA; #ifdef DEBUG fprintf (stderr, "blocks = %d, rest=%d/n", blocks, rest); #endif lseek (fd, 0, SEEK_SET); for (i = 0; i < blocks; i++) { if (write(fd, oneMegaBuffer, ONE_MEGA) < 0) { throwIOException(env, "Cannot initialize file"); return; } } if (rest != 0l) { if (write(fd, oneMegaBuffer, rest) < 0) { throwIOException(env, "Cannot initialize file"); return; } } lseek (fd, 0, SEEK_SET);}
开发者ID:bershath,项目名称:activemq-artemis,代码行数:32,
示例7: RandomAccessFile_setLengthvoid RandomAccessFile_setLength (JNIEnv *env, w_instance thisRAF, w_long newlen) { w_instance fd_obj; vfs_FILE *file; fd_obj = getReferenceField(thisRAF, F_RandomAccessFile_fd); file = getWotsitField(fd_obj, F_FileDescriptor_fd); if(file == NULL) { throwNullPointerException(JNIEnv2w_thread(env)); } else { char *pathname; w_long oldptr; pathname = getFDName(fd_obj); oldptr = vfs_ftell(file); if(vfs_truncate(pathname, newlen) == -1) { throwIOException(JNIEnv2w_thread(env)); } freeFDName(pathname); if(newlen < oldptr && vfs_fseek(file, newlen, SEEK_SET) == -1) { throwIOException(JNIEnv2w_thread(env)); } }}
开发者ID:caizongchao,项目名称:open-mika,代码行数:29,
示例8: create_subprocessstatic int create_subprocess(JNIEnv *env, const char *cmd, char *const argv[], char *const envp[], int masterFd){ // same size as Android 1.6 libc/unistd/ptsname_r.c char devname[64]; pid_t pid; fcntl(masterFd, F_SETFD, FD_CLOEXEC); // grantpt is unnecessary, because we already assume devpts by using /dev/ptmx if(unlockpt(masterFd)){ throwIOException(env, errno, "trouble with /dev/ptmx"); return -1; } memset(devname, 0, sizeof(devname)); // Early (Android 1.6) bionic versions of ptsname_r had a bug where they returned the buffer // instead of 0 on success. A compatible way of telling whether ptsname_r // succeeded is to zero out errno and check it after the call errno = 0; int ptsResult = ptsname_r(masterFd, devname, sizeof(devname)); if (ptsResult && errno) { throwIOException(env, errno, "ptsname_r returned error"); return -1; } pid = fork(); if(pid < 0) { throwIOException(env, errno, "fork failed"); return -1; } if(pid == 0){ int pts; setsid(); pts = open(devname, O_RDWR); if(pts < 0) exit(-1); ioctl(pts, TIOCSCTTY, 0); dup2(pts, 0); dup2(pts, 1); dup2(pts, 2); closeNonstandardFileDescriptors(); if (envp) { for (; *envp; ++envp) { putenv(*envp); } } execv(cmd, argv); exit(-1); } else { return (int) pid; }}
开发者ID:1234hdpa,项目名称:Android-Terminal-Emulator,代码行数:58,
示例9: Java_java_nio_channels_SocketChannel_natThrowWriteErrorextern "C" JNIEXPORT void JNICALLJava_java_nio_channels_SocketChannel_natThrowWriteError(JNIEnv *e, jclass, jint socket){ int error; socklen_t size = sizeof(int); int r = getsockopt(socket, SOL_SOCKET, SO_ERROR, reinterpret_cast<char*>(&error), &size); if (r != 0 or size != sizeof(int)) { throwIOException(e); } else if (error != 0) { throwIOException(e, socketErrorString(e, error)); }}
开发者ID:alexeyshurygin,项目名称:avian,代码行数:15,
示例10: RandomAccessFile_skipBytesw_int RandomAccessFile_skipBytes (JNIEnv *env, w_instance thisRAF, w_int n) { w_thread thread = JNIEnv2w_thread(env); w_instance fd_obj; vfs_FILE *file; w_long result = 0; w_long prev_pos; fd_obj = getReferenceField(thisRAF, F_RandomAccessFile_fd); file = getWotsitField(fd_obj, F_FileDescriptor_fd); if (file == NULL) { throwNullPointerException(thread); } else { struct vfs_STAT statbuf; w_long size = 0; if(statFD(fd_obj, &statbuf)) { size = statbuf.st_size; } else { throwIOException(thread); return -1; } prev_pos = vfs_ftell(file); if (prev_pos < 0) { throwIOException(thread); return -1; } if(n > (size - prev_pos)) { n = size - prev_pos; } result = vfs_fseek(file, (long)n, SEEK_CUR); if (result < 0) { throwIOException(thread); return -1; } result = vfs_ftell(file) - prev_pos; if (result < 0) { throwIOException(thread); } } return result;}
开发者ID:caizongchao,项目名称:open-mika,代码行数:48,
示例11: read0jint read0(JNIEnv * env, jclass clazz, jint fd, void *buffer, jint pos, jint limit) { ssize_t res; int err; do { res = read(fd, buffer + pos, (size_t) (limit - pos)); // Keep on reading if we was interrupted } while (res == -1 && ((err = errno) == EINTR)); if (res < 0) { if (err == EAGAIN || err == EWOULDBLOCK) { // Nothing left to read return 0; } if (err == EBADF) { throwClosedChannelException(env); return -1; } throwIOException(env, exceptionMessage("Error while read(...): ", err)); return -1; } if (res == 0) { // end-of-stream return -1; } return (jint) res;}
开发者ID:ByungChulHwang,项目名称:netty,代码行数:27,
示例12: sendTo0jint sendTo0(JNIEnv * env, jint fd, void* buffer, jint pos, jint limit ,jbyteArray address, jint scopeId, jint port) { struct sockaddr_storage addr; init_sockaddr(env, address, scopeId, port, &addr); ssize_t res; int err; do { res = sendto(fd, buffer + pos, (size_t) (limit - pos), 0, (struct sockaddr *)&addr, sizeof(struct sockaddr_storage)); // keep on writing if it was interrupted } while(res == -1 && ((err = errno) == EINTR)); if (res < 0) { // network stack saturated... try again later if (err == EAGAIN || err == EWOULDBLOCK) { return 0; } if (err == EBADF) { throwClosedChannelException(env); return -1; } throwIOException(env, exceptionMessage("Error while sendto(...): ", err)); return -1; } return (jint) res;}
开发者ID:ByungChulHwang,项目名称:netty,代码行数:25,
示例13: Java_net_java_games_input_LinuxEventDevice_nEraseEffectJNIEXPORT void JNICALL Java_net_java_games_input_LinuxEventDevice_nEraseEffect(JNIEnv *env, jclass unused, jlong fd_address, jint ff_id) { int fd = (int)fd_address; int ff_id_int = ff_id; if (ioctl(fd, EVIOCRMFF, &ff_id_int) == -1) throwIOException(env, "Failed to erase effect (%d)/n", errno);}
开发者ID:Conzar,项目名称:jinput,代码行数:7,
示例14: ioctl/* * Class: com_pi4j_jni_Serial * Method: setDTR * Signature: (IZ)V */JNIEXPORT void JNICALL Java_com_pi4j_jni_Serial_setDTR (JNIEnv *env, jclass obj, jint fd, jboolean enabled){ int status = 0; int ret; status |= TIOCM_DTR; if(enabled == JNI_FALSE) { ret = ioctl(fd, TIOCMBIC, &status); } else { ret = ioctl(fd, TIOCMBIS, &status); } // raise IOException if failed if(ret != 0) { int err_number = errno; char err_message[100]; sprintf(err_message, "Failed to set DTR pin state. (Error #%d)", err_number); throwIOException(env, err_message); }}
开发者ID:alexmao86,项目名称:pi4j,代码行数:31,
示例15: throwRuntimeExceptionJNIEXPORT void JNICALL Java_com_intel_bluetooth_BluetoothStackBlueZ_l2Send (JNIEnv* env, jobject peer, jlong handle, jbyteArray data, jint transmitMTU) {#ifdef BLUECOVE_L2CAP_MTU_TRUNCATE struct l2cap_options opt; if (!l2Get_options(env, handle, &opt)) { return; }#endif //BLUECOVE_L2CAP_MTU_TRUNCATE if (data == NULL) { throwRuntimeException(env, "Invalid argument"); return; } jbyte *bytes = (*env)->GetByteArrayElements(env, data, 0); if (bytes == NULL) { throwRuntimeException(env, "Invalid argument"); return; } int len = (int)(*env)->GetArrayLength(env, data); if (len > transmitMTU) { len = transmitMTU; }#ifdef BLUECOVE_L2CAP_MTU_TRUNCATE if (len > opt.omtu) { len = opt.omtu; }#endif //BLUECOVE_L2CAP_MTU_TRUNCATE int count = send(handle, (char *)bytes, len, 0); if (count < 0) { throwIOException(env, "Failed to write. [%d] %s", errno, strerror(errno)); } (*env)->ReleaseByteArrayElements(env, data, bytes, 0);}
开发者ID:AfonsodelCB,项目名称:bluecove,代码行数:35,
示例16: printf/* * Class: com_pi4j_jni_Serial * Method: setBreak * Signature: (IZ)V */JNIEXPORT void JNICALL Java_com_pi4j_jni_Serial_setBreak (JNIEnv *env, jclass obj, jint fd, jboolean enabled){ if(enabled == JNI_FALSE) { printf("SERIAL SET BREAK - FALSE/n"); if(ioctl(fd, TIOCCBRK, NULL) == 0) { printf("SERIAL SET BREAK - SUCCESS/n"); return; } } else { printf("SERIAL SET BREAK - TRUE/n"); if(ioctl(fd, TIOCSBRK, NULL) == 0) { printf("SERIAL SET BREAK - SUCCESS/n"); return; } } printf("SERIAL SET BREAK - ERROR/n"); // raise IOException if failed int err_number = errno; char err_message[100]; sprintf(err_message, "Failed to set RTS pin state. (Error #%d)", err_number); throwIOException(env, err_message);}
开发者ID:alexmao86,项目名称:pi4j,代码行数:34,
示例17: recvFrom0jobject recvFrom0(JNIEnv * env, jint fd, void* buffer, jint pos, jint limit) { struct sockaddr_storage addr; socklen_t addrlen = sizeof(addr); ssize_t res; int err; do { res = recvfrom(fd, buffer + pos, (size_t) (limit - pos), 0, (struct sockaddr *)&addr, &addrlen); // Keep on reading if we was interrupted } while (res == -1 && ((err = errno) == EINTR)); if (res < 0) { if (err == EAGAIN || err == EWOULDBLOCK) { // Nothing left to read return NULL; } if (err == EBADF) { throwClosedChannelException(env); return NULL; } throwIOException(env, exceptionMessage("Error while recvFrom(...): ", err)); return NULL; } return createDatagramSocketAddress(env, addr, res);}
开发者ID:ByungChulHwang,项目名称:netty,代码行数:26,
示例18: throwRuntimeExceptionJNIEXPORT void JNICALL Java_com_intel_bluetooth_BluetoothStackBlueZDBus_connectionRfWrite__J_3BII (JNIEnv* env, jobject peer, jlong handle, jbyteArray b, jint off, jint len) { if (b == NULL) { throwRuntimeException(env, "Invalid argument"); return; } jbyte *bytes = (*env)->GetByteArrayElements(env, b, 0); if (bytes == NULL) { throwRuntimeException(env, "Invalid argument"); return; } int done = 0; while(done < len) { int count = send(handle, (char *)(bytes + off + done), len - done, 0); if (count < 0) { throwIOException(env, "Failed to write. [%d] %s", errno, strerror(errno)); break; } if (isCurrentThreadInterrupted(env, peer)) { break; } done += count; } (*env)->ReleaseByteArrayElements(env, b, bytes, 0);}
开发者ID:AfonsodelCB,项目名称:bluecove,代码行数:25,
示例19: getIOControlJNIEXPORT void JNICALL Java_org_apache_activemq_artemis_jlibaio_LibaioContext_submitWrite (JNIEnv * env, jclass clazz, jint fileHandle, jobject contextPointer, jlong position, jint size, jobject bufferWrite, jobject callback) { struct io_control * theControl = getIOControl(env, contextPointer); if (theControl == NULL) { return; } #ifdef DEBUG fprintf (stdout, "submitWrite position %ld, size %d/n", position, size); #endif struct iocb * iocb = getIOCB(theControl); if (iocb == NULL) { throwIOException(env, "Not enough space in libaio queue"); return; } io_prep_pwrite(iocb, fileHandle, getBuffer(env, bufferWrite), (size_t)size, position); // The GlobalRef will be deleted when poll is called. this is done so // the vm wouldn't crash if the Callback passed by the user is GCed between submission // and callback. // also as the real intention is to hold the reference until the life cycle is complete iocb->data = (void *) (*env)->NewGlobalRef(env, callback); submit(env, theControl, iocb);}
开发者ID:jamezp,项目名称:activemq-artemis,代码行数:28,
示例20: throwIOExceptionJNIEXPORT void JNICALL Java_com_intel_bluetooth_BluetoothStackBlueZDBus_connectionRfWrite__JI (JNIEnv* env, jobject peer, jlong handle, jint b) { char c = (char)b; if (send(handle, &c, 1, 0) != 1) { throwIOException(env, "Failed to write. [%d] %s", errno, strerror(errno)); }}
开发者ID:AfonsodelCB,项目名称:bluecove,代码行数:7,
示例21: getAvailableByteCount/* * Class: com_pi4j_jni_Serial * Method: read * Signature: (II)[B */JNIEXPORT jbyteArray JNICALL Java_com_pi4j_jni_Serial_read__II (JNIEnv *env, jclass obj, jint fd, jint length){ // determine result data array length from the number of bytes available on the receive buffer int availableBytes; availableBytes = getAvailableByteCount(fd); // check for error return; if error, then return NULL if (availableBytes < 0){ int err_number = errno; char err_message[100]; sprintf(err_message, "Error attempting to read data from serial port. (Error #%d)", err_number); throwIOException(env, err_message); return (*env)->NewByteArray(env, 0); // ERROR READING RX BUFFER } // reduce length if it exceeds the number available if(length > availableBytes){ length = availableBytes; } // create a new payload result byte array jbyte result[length]; // copy the data bytes from the serial receive buffer into the payload result int i; for (i = 0; i < length; i++) { // read a single byte from the RX buffer uint8_t x ; if (read (fd, &x, 1) != 1){ int err_number = errno; char err_message[100]; sprintf(err_message, "Failed to read data from serial port. (Error #%d)", err_number); throwIOException(env, err_message); return (*env)->NewByteArray(env, 0); // ERROR READING RX BUFFER } // assign the single byte; cast to unsigned char result[i] = (unsigned char)(((int)x) & 0xFF); } // create a java array object and copy the raw payload bytes jbyteArray javaResult = (*env)->NewByteArray(env, length); (*env)->SetByteArrayRegion(env, javaResult, 0, length, result); return javaResult;}
开发者ID:alexmao86,项目名称:pi4j,代码行数:52,
示例22: l2Get_optionsbool l2Get_options(JNIEnv* env, jlong handle, struct l2cap_options* opt) { socklen_t opt_len = sizeof(*opt); if (getsockopt(handle, SOL_L2CAP, L2CAP_OPTIONS, opt, &opt_len) < 0) { throwIOException(env, "Failed to get L2CAP link mtu. [%d] %s", errno, strerror(errno)); return false; } return true;}
开发者ID:rahulopengts,项目名称:bluetooth,代码行数:8,
示例23: Java_net_java_games_input_LinuxEventDevice_nGrabJNIEXPORT jint JNICALL Java_net_java_games_input_LinuxEventDevice_nGrab(JNIEnv *env, jclass unused, jlong fd_address, jint do_grab) { int fd = (int)fd_address; int grab = (int)do_grab; if (ioctl(fd,EVIOCGRAB,grab) == -1){ throwIOException(env, "Failed to grab device (%d)/n", errno); return -1; } return 1;}
开发者ID:JogAmp,项目名称:jinput,代码行数:9,
示例24: Java_net_java_games_input_LinuxEventDevice_nGetNumEffectsJNIEXPORT jint JNICALL Java_net_java_games_input_LinuxEventDevice_nGetNumEffects(JNIEnv *env, jclass unused, jlong fd_address) { int fd = (int)fd_address; int num_effects; if (ioctl(fd, EVIOCGEFFECTS, &num_effects) == -1) { throwIOException(env, "Failed to get number of device effects (%d)/n", errno); return -1; } return num_effects;}
开发者ID:Conzar,项目名称:jinput,代码行数:9,
示例25: Java_net_java_games_input_LinuxEventDevice_nGetVersionJNIEXPORT jint JNICALL Java_net_java_games_input_LinuxEventDevice_nGetVersion(JNIEnv *env, jclass unused, jlong fd_address) { int fd = (int)fd_address; int version; if (ioctl(fd, EVIOCGVERSION, &version) == -1) { throwIOException(env, "Failed to get device version (%d)/n", errno); return -1; } return version;}
开发者ID:Conzar,项目名称:jinput,代码行数:9,
示例26: Java_io_netty_channel_epoll_Native_bindJNIEXPORT void JNICALL Java_io_netty_channel_epoll_Native_bind(JNIEnv * env, jclass clazz, jint fd, jbyteArray address, jint scopeId, jint port) { struct sockaddr_storage addr; init_sockaddr(env, address, scopeId, port, &addr); if(bind(fd, (struct sockaddr *) &addr, sizeof(addr)) == -1){ int err = errno; throwIOException(env, exceptionMessage("Error during bind(...): ", err)); }}
开发者ID:ByungChulHwang,项目名称:netty,代码行数:9,
注:本文中的throwIOException函数示例整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。 C++ throwIfNotWorkItemThread函数代码示例 C++ threshold函数代码示例 |