public static unsafe void WriteAsciiString(ref WritableBuffer buffer, string value) { // One byte per char buffer.Ensure(value.Length); fixed(char *s = value) { int written = Encoding.ASCII.GetBytes(s, value.Length, (byte *)buffer.Memory.BufferPtr, value.Length); buffer.UpdateWritten(written); } }
public static unsafe void WriteUtf8String(ref WritableBuffer buffer, string value) { var encoding = Encoding.UTF8; fixed(char *s = value) { var byteCount = encoding.GetByteCount(value); buffer.Ensure(byteCount); int written = encoding.GetBytes(s, value.Length, (byte *)buffer.Memory.BufferPtr, byteCount); buffer.UpdateWritten(written); } }
private void OnRead(UvStreamHandle handle, int status) { if (status == 0) { // A zero status does not indicate an error or connection end. It indicates // there is no data to be read right now. // See the note at http://docs.libuv.org/en/v1.x/stream.html#c.uv_read_cb. // We need to clean up whatever was allocated by OnAlloc. return; } var normalRead = status > 0; var normalDone = status == EOF; var errorDone = !(normalDone || normalRead); var readCount = normalRead ? status : 0; if (normalRead) { // Log.ConnectionRead(ConnectionId, readCount); } else { handle.ReadStop(); } _buffer.UpdateWritten(readCount); IOException error = null; if (errorDone) { Exception uvError; handle.Libuv.Check(status, out uvError); error = new IOException(uvError.Message, uvError); _input.CompleteWriting(error); } else if (readCount == 0) { _input.CompleteWriting(); } else { _input.WriteAsync(_buffer); } }
public void Complete(int status, long requestCorrelation, uint bytesTransferred) { // Receives if (requestCorrelation >= 0) { if (bytesTransferred > 0) { _buffer.UpdateWritten((int)bytesTransferred); _input.WriteAsync(_buffer); ProcessReceives(); } else { _input.CompleteWriting(); } } else { SendCompleting(requestCorrelation); } }
public void CommitBytes(int bytes) { _writableBuffer.UpdateWritten(bytes); }