public read ( byte buffer, int pos, int length ) : int | ||
buffer | byte | |
pos | int | |
length | int | |
Résultat | int |
private void readTransport() { //EDB.WriteLine("READ - "+transport.poll_set); if (dropped || reading) { return; } lock (read_mutex) { reading = true; ReadFinishedFunc callback; uint size; while (!dropped && read_callback != null) { if (read_buffer == null || read_callback == null) { throw new Exception("YOU SUCK!"); } uint to_read = read_size - read_filled; if (to_read > 0) { int bytes_read = transport.read(ref read_buffer, read_filled, to_read); if (dropped) { return; } if (bytes_read < 0) { callback = read_callback; read_callback = null; byte[] buffer = read_buffer; read_buffer = null; size = read_size; read_size = 0; read_filled = 0; callback(this, ref buffer, size, false); break; } read_filled += (uint)bytes_read; } else { break; } if (read_filled == read_size && !dropped) { callback = read_callback; size = read_size; byte[] buffer = read_buffer; read_buffer = null; read_callback = null; read_size = 0; callback(this, ref buffer, size, true); } else { break; } } if (read_callback == null) { transport.disableRead(); } reading = false; } }
private void readTransport() { lock (reading) { //EDB.WriteLine("READ - "+transport.poll_set); if (dropped) { return; } ScopedTimer.Ping(); ReadFinishedFunc callback; lock (read_callback_mutex) callback = read_callback; int size; while (!dropped && callback != null) { ScopedTimer.Ping(); int to_read = read_size - read_filled; if (to_read > 0 && read_buffer == null) { throw new Exception("Trying to read " + to_read + " bytes with a null read_buffer!"); } if (callback == null) { lock (read_callback_mutex) callback = read_callback; } if (callback == null) { throw new Exception("Cannot determine which read_callback to invoke?!"); } if (to_read > 0) { ScopedTimer.Ping(); int bytes_read = transport.read(read_buffer, read_filled, to_read); if (dropped) { if (read_callback == null) { transport.disableRead(); } break; } if (bytes_read < 0) { ScopedTimer.Ping(); read_callback = null; byte[] buffer = read_buffer; read_buffer = null; size = read_size; read_size = 0; read_filled = 0; #if BEGIN_INVOKE callback.BeginInvoke(this, buffer, size, false, readTransportComplete, callback); #else if (!callback(this, buffer, size, false)) { Console.WriteLine("Callbacks invoked by connection errored"); } callback = null; lock (read_callback_mutex) if (read_callback == null) { transport.disableRead(); } #endif break; } lock (read_callback_mutex) callback = read_callback; read_filled += bytes_read; } else { lock (read_callback_mutex) if (read_callback == null) { transport.disableRead(); } break; } if (read_filled == read_size && !dropped) { size = read_size; byte[] buffer = read_buffer; read_buffer = null; lock (read_callback_mutex) read_callback = null; read_size = 0; #if BEGIN_INVOKE callback.BeginInvoke(this, buffer, size, true, readTransportComplete, callback); #else if (!callback(this, buffer, size, true)) { Console.WriteLine("Callbacks invoked by connection errored"); } lock (read_callback_mutex) if (read_callback == null) { transport.disableRead(); } #endif callback = null; } else { lock (read_callback_mutex) if (read_callback == null) { transport.disableRead(); } break; } } } }