public void read(uint size, ReadFinishedFunc finished_func) { if (dropped || sendingHeaderError) { return; } lock (read_mutex) { if (read_callback != null) { throw new Exception("NOYOUBLO"); } read_callback = finished_func; if (size == 4) { read_buffer = length_buffer; } else { if (real_read_buffer == null || real_read_buffer.Length != size) { real_read_buffer = new byte[size]; } read_buffer = real_read_buffer; } read_size = size; read_filled = 0; transport.enableRead(); readTransport(); } }
public void read(int size, ReadFinishedFunc finished_func) { if (dropped || sendingHeaderError) { return; } lock ( read_callback_mutex ) { if (read_callback != null) { throw new InvalidOperationException("Multiple concurrent read operations are not allowed (read_callback is not null)."); } read_callback = finished_func; } if (size == 4) { read_buffer = length_buffer; } else { if (real_read_buffer == null || real_read_buffer.Length != size) { real_read_buffer = new byte[size]; } read_buffer = real_read_buffer; } read_size = size; read_filled = 0; transport.enableRead(); readTransport(); }
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; } }
public void read(uint size, ReadFinishedFunc finished_func) { if (dropped || sendingHeaderError) return; lock (read_mutex) { if (read_callback != null) throw new Exception("NOYOUBLO"); read_callback = finished_func; if (size == 4) read_buffer = length_buffer; else { if (real_read_buffer == null || real_read_buffer.Length != size) real_read_buffer = new byte[size]; read_buffer = real_read_buffer; } read_size = size; read_filled = 0; transport.enableRead(); readTransport(); } }
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; } } } }
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; } } } }
private void readTransport() { lock ( reading ) { //ROS.Debug()( $"[{ThisNode.Name}] READ - {transport.poll_set}" ); if (dropped) { return; } ReadFinishedFunc callback; lock (read_callback_mutex) callback = read_callback; int size; while (!dropped && callback != null) { int to_read = read_size - read_filled; if (to_read > 0 && read_buffer == null) { throw new Exception($"[{ThisNode.Name}] 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($"[{ThisNode.Name}] Cannot determine which read_callback to invoke."); } if (to_read > 0) { int bytes_read = transport.read(read_buffer, read_filled, to_read); if (dropped) { if (read_callback == null) { transport.disableRead(); } break; } if (bytes_read < 0) { read_callback = null; byte[] buffer = read_buffer; read_buffer = null; size = read_size; read_size = 0; read_filled = 0; if (!callback(this, buffer, size, false)) { ROS.Error()($"[{ThisNode.Name}] Callbacks invoked by connection errored"); } callback = null; lock ( read_callback_mutex ) { if (read_callback == null) { transport.disableRead(); } 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 (!callback(this, buffer, size, true)) { ROS.Error()($"[{ThisNode.Name}] Callbacks invoked by connection errored"); } lock ( read_callback_mutex ) { if (read_callback == null) { transport.disableRead(); } } callback = null; } else { lock ( read_callback_mutex ) { if (read_callback == null) { transport.disableRead(); } } break; } } } }