public bool Flush(ServerSock socket) { try { if (socket == null || !socket.active) { return(false); } if (buffers[socket.whoAmI].Count < 1) { return(false); } byte[] buff = buffers[socket.whoAmI].GetBytes(BytesPerUpdate); if (buff == null) { return(false); } if (SendBytes(socket, buff)) { buffers[socket.whoAmI].Pop(buff.Length); return(true); } } catch (Exception e) { Log.ConsoleError(e.ToString()); } return(false); }
public bool SendBytes(ServerSock socket, byte[] buffer, int offset, int count) { try { if (socket.tcpClient.Client != null && socket.tcpClient.Client.Poll(0, SelectMode.SelectWrite)) { if (Main.runningMono) { socket.networkStream.Write(buffer, offset, count); } else { socket.tcpClient.Client.Send(buffer, offset, count, SocketFlags.None); } return(true); } } catch (ObjectDisposedException) { } catch (SocketException) { } catch (IOException) { } return(false); }
public static void OnSocketReset(ServerSock socket) { if (ServerHooks.SocketReset != null) { ServerHooks.SocketReset(socket); } }
internal void InvokeServerSocketReset(ServerSock socket) { SocketResetEventArgs args = new SocketResetEventArgs { Socket = socket }; this.ServerSocketReset.Invoke(args); }
public bool SendBytes(ServerSock socket, byte[] buffer, int offset, int count) { try { if (socket.tcpClient.Client != null && socket.tcpClient.Client.Poll(0, SelectMode.SelectWrite)) { if (ServerApi.RunningMono && !ServerApi.UseAsyncSocketsInMono) { socket.networkStream.Write(buffer, offset, count); } else { socket.networkStream.BeginWrite(buffer, offset, count, socket.ServerWriteCallBack, socket.networkStream); } return(true); } } catch (ObjectDisposedException e) { Log.Warn(e.ToString()); } catch (SocketException e) { switch ((uint)e.ErrorCode) { case 0x80004005: case 10053: break; default: Log.Warn(e.ToString()); break; } } catch (IOException e) { if (e.InnerException is SocketException) { switch (((SocketException)e.InnerException).SocketErrorCode) { case SocketError.Shutdown: case SocketError.ConnectionReset: break; default: Log.Warn(e.ToString()); break; } } else { Log.Warn(e.ToString()); } } return(false); }
/// <summary> /// Send bytes to client using packetbuffering if available /// </summary> /// <param name="client">socket to send to</param> /// <param name="bytes">bytes to send</param> /// <returns>False on exception</returns> public static bool SendBytes(ServerSock client, byte[] bytes) { if (PacketBuffer != null) { PacketBuffer.BufferBytes(client, bytes); return(true); } return(SendBytesBufferless(client, bytes)); }
public static bool OnSendBytes(ServerSock socket, byte[] buffer, int offset, int count) { if (NetHooks.SendBytes == null) { return(false); } HandledEventArgs handledEventArgs = new HandledEventArgs(); NetHooks.SendBytes(socket, buffer, offset, count, handledEventArgs); return(handledEventArgs.Handled); }
public static bool OnSendBytes(ServerSock socket, byte[] buffer, int offset, int count) { if (SendBytes == null) { return(false); } var args = new HandledEventArgs(); SendBytes(socket, buffer, offset, count, args); return(args.Handled); }
internal bool InvokeNetSendBytes(ServerSock socket, byte[] buffer, int offset, int count) { SendBytesEventArgs args = new SendBytesEventArgs { Socket = socket, Buffer = buffer, Offset = offset, Count = count }; this.NetSendBytes.Invoke(args); return(args.Handled); }
/// <summary> /// Send bytes to a client ignoring the packet buffer /// </summary> /// <param name="client">socket to send to</param> /// <param name="bytes">bytes to send</param> /// <returns>False on exception</returns> public static bool SendBytesBufferless(ServerSock client, byte[] bytes) { try { if (client.tcpClient.Connected) { client.networkStream.Write(bytes, 0, bytes.Length); } return(true); } catch (Exception ex) { Log.Warn("This is a normal exception"); Log.Warn(ex.ToString()); } return(false); }
public void BufferBytes(ServerSock socket, byte[] buffer, int offset, int count) { lock (buffers[socket.whoAmI]) { #if DEBUG_NET int size = (count - offset); var pt = buffer[offset + 4]; Packets[pt]++; Bytes[pt] += size; Compressed[pt] += Compress(buffer, offset, count); #endif using (var ms = new MemoryStream(buffer, offset, count)) { buffers[socket.whoAmI].AddRange(ms.ToArray()); } } }
public bool SendBytes(ServerSock socket, byte[] buffer, int offset, int count) { try { if (socket.tcpClient.Client != null && socket.tcpClient.Client.Poll(0, SelectMode.SelectWrite)) { if (Main.runningMono) { socket.networkStream.Write(buffer, offset, count); } else { socket.tcpClient.Client.Send(buffer, offset, count, SocketFlags.None); } return(true); } } catch (ObjectDisposedException e) { Log.Warn(e.ToString()); } catch (SocketException e) { switch ((uint)e.ErrorCode) { case 0x80004005: case 10053: break; default: Log.Warn(e.ToString()); break; } } catch (IOException e) { Log.Warn(e.ToString()); } return(false); }
public void BufferBytes(ServerSock socket, byte[] buffer, int offset, int count) { lock (buffers[socket.whoAmI]) { #if DEBUG_NET int size = (count - offset); var pt = buffer[offset + 4]; Packets[pt]++; Bytes[pt] += size; Compressed[pt] += Compress(buffer, offset, count); #endif using (var ms = new MemoryStream(buffer, offset, count)) { buffers[socket.whoAmI].AddRange(ms.ToArray()); } if (TShock.Config.EnableMaxBytesInBuffer && buffers[socket.whoAmI].Count > TShock.Config.MaxBytesInBuffer) { buffers[socket.whoAmI].Clear(); socket.kill = true; } } }
public void setSocket(ServerSock Socket) { socket = Socket; }
public void BufferBytes(ServerSock socket, byte[] buffer) { BufferBytes(socket, buffer, 0, buffer.Length); }
public bool SendBytes(ServerSock socket, byte[] buffer) { return(SendBytes(socket, buffer, 0, buffer.Length)); }
void ServerHooks_SocketReset(ServerSock socket) { buffers[socket.whoAmI] = new PacketBuffer(); }
void ServerHooks_SendBytes(ServerSock socket, byte[] buffer, int offset, int count, HandledEventArgs e) { e.Handled = true; BufferBytes(socket, buffer, offset, count); }