1 // =================================
 2 // Copyright (c) 2021 Seppo Laakko
 3 // Distributed under the MIT license
 4 // =================================
 5 
 6 using System;
 7 using System.IO;
 8 
 9 namespace System.Net.Sockets
10 {
11     public class NetworkByteStream : ByteStream
12     {
13         public nothrow NetworkByteStream(TcpSocket&& socket_) : socket(socket_)
14         {
15         }
16         public override int ReadByte()
17         {
18             byte buf;
19             long bytesRead = Read(&buf1);
20             if (bytesRead == 0)
21             {
22                 return -1;
23             }
24             else
25             {
26                 return buf;
27             }
28         }
29         public override long Read(byte* buflong count)
30         {
31             if (buf == null)
32             {
33                 ThrowInvalidParameterException();
34             }
35             if (count < 0)
36             {
37                 ThrowInvalidParameterException();
38             }
39             return socket.Receive(bufcast<int>(count));
40         }
41         public override void Write(byte x)
42         {
43             Write(&x1);
44         }
45         public override void Write(byte* buflong count)
46         {
47             if (buf == null)
48             {
49                 ThrowInvalidParameterException();
50             }
51             if (count < 0)
52             {
53                 ThrowInvalidParameterException();
54             }
55             socket.Send(bufcast<int>(count));
56         }
57         public TcpSocket& ContainedSocket()
58         {
59             return socket;
60         }
61         private TcpSocket socket;
62     }
63 }