mirror of
https://github.com/ClassiCube/ClassiCube.git
synced 2025-09-29 08:32:46 -04:00
Use raw socket receive/send instead of NetworkStream.
This commit is contained in:
parent
ff4b1eb723
commit
0936dd7e50
@ -43,9 +43,8 @@ namespace ClassicalSharp.Network {
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
NetworkStream stream = new NetworkStream( socket, true );
|
reader = new NetReader( socket );
|
||||||
reader = new NetReader( stream );
|
writer = new NetWriter( socket );
|
||||||
writer = new NetWriter( stream );
|
|
||||||
gzippedMap = new FixedBufferStream( reader.buffer );
|
gzippedMap = new FixedBufferStream( reader.buffer );
|
||||||
|
|
||||||
Disconnected = false;
|
Disconnected = false;
|
||||||
|
@ -8,25 +8,25 @@ namespace ClassicalSharp.Network {
|
|||||||
|
|
||||||
public byte[] buffer = new byte[4096 * 5];
|
public byte[] buffer = new byte[4096 * 5];
|
||||||
public int index = 0, size = 0;
|
public int index = 0, size = 0;
|
||||||
public NetworkStream Stream;
|
Socket socket;
|
||||||
|
|
||||||
public NetReader( NetworkStream stream ) {
|
public NetReader( Socket socket ) {
|
||||||
Stream = stream;
|
this.socket = socket;
|
||||||
}
|
}
|
||||||
|
|
||||||
public void ReadPendingData() {
|
public void ReadPendingData() {
|
||||||
if( !Stream.DataAvailable ) return;
|
if( socket.Available == 0 ) return;
|
||||||
// NOTE: Always using a read call that is a multiple of 4096
|
// NOTE: Always using a read call that is a multiple of 4096
|
||||||
// (appears to?) improve read performance.
|
// (appears to?) improve read performance.
|
||||||
int received = Stream.Read( buffer, size, 4096 * 4 );
|
int recv = socket.Receive( buffer, size, 4096 * 4, SocketFlags.None );
|
||||||
size += received;
|
size += recv;
|
||||||
}
|
}
|
||||||
|
|
||||||
public void Skip( int byteCount ) {
|
public void Skip( int byteCount ) {
|
||||||
index += byteCount;
|
index += byteCount;
|
||||||
}
|
}
|
||||||
|
|
||||||
public void RemoveProcessed() {
|
public void RemoveProcessed() {
|
||||||
size -= index;
|
size -= index;
|
||||||
if( size > 0 ) // only copy left over bytes
|
if( size > 0 ) // only copy left over bytes
|
||||||
Buffer.BlockCopy( buffer, index, buffer, 0, size );
|
Buffer.BlockCopy( buffer, index, buffer, 0, size );
|
||||||
|
@ -8,10 +8,10 @@ namespace ClassicalSharp.Network {
|
|||||||
|
|
||||||
public byte[] buffer = new byte[131];
|
public byte[] buffer = new byte[131];
|
||||||
public int index = 0;
|
public int index = 0;
|
||||||
public NetworkStream Stream;
|
Socket socket;
|
||||||
|
|
||||||
public NetWriter( NetworkStream stream ) {
|
public NetWriter( Socket socket ) {
|
||||||
Stream = stream;
|
this.socket = socket;
|
||||||
}
|
}
|
||||||
|
|
||||||
public void WriteString( string value ) {
|
public void WriteString( string value ) {
|
||||||
@ -54,7 +54,9 @@ namespace ClassicalSharp.Network {
|
|||||||
}
|
}
|
||||||
|
|
||||||
public void Send() {
|
public void Send() {
|
||||||
Stream.Write( buffer, 0, index );
|
int offset = 0;
|
||||||
|
while( offset < index )
|
||||||
|
offset += socket.Send( buffer, offset, index - offset, SocketFlags.None );
|
||||||
index = 0;
|
index = 0;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user