JNIEXPORT jlong JNICALL Java_io_netty_channel_epoll_Native_writev(JNIEnv * env, jclass clazz, jint fd, jobjectArray buffers, jint offset, jint length) { struct iovec iov[length]; int i; int iovidx = 0; for (i = offset; i < length; i++) { jobject bufObj = (*env)->GetObjectArrayElement(env, buffers, i); jint pos; // Get the current position using the (*env)->GetIntField if possible and fallback // to slower (*env)->CallIntMethod(...) if needed if (posFieldId == NULL) { pos = (*env)->CallIntMethod(env, bufObj, posId, NULL); } else { pos = (*env)->GetIntField(env, bufObj, posFieldId); } jint limit; // Get the current limit using the (*env)->GetIntField if possible and fallback // to slower (*env)->CallIntMethod(...) if needed if (limitFieldId == NULL) { limit = (*env)->CallIntMethod(env, bufObj, limitId, NULL); } else { limit = (*env)->GetIntField(env, bufObj, limitFieldId); } void *buffer = (*env)->GetDirectBufferAddress(env, bufObj); if (buffer == NULL) { throwRuntimeException(env, "Unable to access address of buffer"); return -1; } iov[iovidx].iov_base = buffer + pos; iov[iovidx].iov_len = (size_t) (limit - pos); iovidx++; } jlong res = writev0(env, clazz, fd, iov, length); if (res <= 0) { return res; } // update the position of the written buffers int written = res; int a; for (a = 0; a < length; a++) { int len = iov[a].iov_len; jobject bufObj = (*env)->GetObjectArrayElement(env, buffers, a + offset); if (len >= written) { incrementPosition(env, bufObj, written); break; } else { incrementPosition(env, bufObj, len); written -= len; } } return res; }
bool MySQLResult::next() const { _row = mysql_fetch_row(_result); _lengths = mysql_fetch_lengths(_result); incrementPosition(); return _row != NULL; }
void U3DBitStreamWriter::alignTo4Byte() { if(_dataBitOffset > 0) { _dataBitOffset = 0; incrementPosition(); } }
void OSCMessage::getString(char * buffer){ //check position incrementPosition(); while(*dataPtr){ *buffer++ = *dataPtr++; } //null terminated *buffer = '\0'; }
int OSCMessage::getBlob(uint8_t * buffer){ incrementPosition(); //get the length int len = getIntFromDataSection(); //fill the buffer for (int i = 0; i < len; i++){ *buffer++ = *dataPtr++; } return len; }
void U3DBitStreamWriter::alignToByte() { // Check input(s) MLuint32 uBitCount = getBitCount(); uBitCount = (8 - (uBitCount & 7)) & 7; _dataBitOffset += uBitCount; if(_dataBitOffset >= 32) { _dataBitOffset -= 32; incrementPosition(); } }
JNIEXPORT jint JNICALL Java_io_netty_channel_epoll_Native_write(JNIEnv * env, jclass clazz, jint fd, jobject jbuffer, jint pos, jint limit) { void *buffer = (*env)->GetDirectBufferAddress(env, jbuffer); if (buffer == NULL) { throwRuntimeException(env, "Unable to access address of buffer"); return -1; } jint res = write0(env, clazz, fd, buffer, pos, limit); if (res > 0) { // Increment the pos of the ByteBuffer as it may be only partial written to prevent data-corruption later once we // try to write the remaining data. // See https://github.com/netty/netty/issues/2371 incrementPosition(env, jbuffer, res); } return res; }
/* * writeBit * Write the given bit to the datablock. */ void U3DBitStreamWriter::writeBit(MLuint32 bit) { // NOTE: Shift operations on U32s are only valid for shifts of 0 to 31 bits. MLuint32 mask = 1; bit &= mask; _dataLocal &= ~(mask << _dataBitOffset); _dataLocal |= (bit << _dataBitOffset); _dataBitOffset += 1; if(_dataBitOffset >= 32) { _dataBitOffset -= 32; incrementPosition(); } }
//! Writes char data to the file from the supplied buffer bool MrcFileImpl::writeCharData(unsigned char* buffer, unsigned int numSamples, unsigned int variable) { if (m_OpenMode == Read) return false; if (variable>=m_NumVariables || m_VariableTypes[variable]!=Char) { // no good return false; } prepareToRead(variable); // write out the data if ((int)numSamples != m_File.writeBlock((char*)buffer, numSamples)) { return false; } incrementPosition(numSamples); return true; }
//! Reads double data from the file into the supplied buffer bool MrcFileImpl::readDoubleData(double* buffer, unsigned int numSamples, unsigned int variable) { if (m_OpenMode == Write) return false; if (variable>=m_NumVariables || m_VariableTypes[variable]!=Double) { // no good return false; } prepareToRead(variable); // read in the data if ((int)(numSamples*sizeof(double)) != m_File.readBlock((char*)buffer, numSamples*sizeof(double))) { return false; } if (m_MustSwap) swapByteOrder(buffer, numSamples); incrementPosition(numSamples); return true; }
//! Writes float data to the file from the supplied buffer bool MrcFileImpl::writeFloatData(float* buffer, unsigned int numSamples, unsigned int variable) { if (m_OpenMode == Read) return false; if (variable>=m_NumVariables || m_VariableTypes[variable]!=Float) { // no good return false; } prepareToRead(variable); if (m_MustSwap) swapByteOrder(buffer, numSamples); // write out the data if (((int)numSamples*sizeof(float)) != m_File.writeBlock((char*)buffer, numSamples*sizeof(float))) { return false; } incrementPosition(numSamples); return true; }
float OSCMessage::getFloat(){ //check position incrementPosition(); return getFloatFromDataSection(); }
int OSCMessage::getInt(){ //check position incrementPosition(); //get the int from the data pointer return getIntFromDataSection(); }
JNIEXPORT jlong JNICALL Java_io_netty_channel_epoll_Native_writev(JNIEnv * env, jclass clazz, jint fd, jobjectArray buffers, jint offset, jint length) { struct iovec iov[length]; int i; int iovidx = 0; for (i = offset; i < length; i++) { jobject bufObj = (*env)->GetObjectArrayElement(env, buffers, i); jint pos; // Get the current position using the (*env)->GetIntField if possible and fallback // to slower (*env)->CallIntMethod(...) if needed if (posFieldId == NULL) { pos = (*env)->CallIntMethod(env, bufObj, posId, NULL); } else { pos = (*env)->GetIntField(env, bufObj, posFieldId); } jint limit; // Get the current limit using the (*env)->GetIntField if possible and fallback // to slower (*env)->CallIntMethod(...) if needed if (limitFieldId == NULL) { limit = (*env)->CallIntMethod(env, bufObj, limitId, NULL); } else { limit = (*env)->GetIntField(env, bufObj, limitFieldId); } void *buffer = (*env)->GetDirectBufferAddress(env, bufObj); if (buffer == NULL) { throwRuntimeException(env, "Unable to access address of buffer"); return -1; } iov[iovidx].iov_base = buffer + pos; iov[iovidx].iov_len = (size_t) (limit - pos); iovidx++; // Explicit delete local reference as otherwise the local references will only be released once the native method returns. // Also there may be a lot of these and JNI specification only specify that 16 must be able to be created. // // See https://github.com/netty/netty/issues/2623 (*env)->DeleteLocalRef(env, bufObj); } jlong res = writev0(env, clazz, fd, iov, length); if (res <= 0) { return res; } // update the position of the written buffers int written = res; int a; for (a = 0; a < length; a++) { int len = iov[a].iov_len; jobject bufObj = (*env)->GetObjectArrayElement(env, buffers, a + offset); if (len >= written) { incrementPosition(env, bufObj, written); break; } else { incrementPosition(env, bufObj, len); written -= len; } // Explicit delete local reference as otherwise the local references will only be released once the native method returns. // Also there may be a lot of these and JNI specification only specify that 16 must be able to be created. // // See https://github.com/netty/netty/issues/2623 (*env)->DeleteLocalRef(env, bufObj); } return res; }