Simulcast.NET Stream

Firstly, I want to be clear that I do not mean the simultaneous transmission of the TCP / IP stream, I want to take the output of the C # stream and translate it to several purposes.

For example, if I had FileStream (fs) and MemoryStream (ms) and FtpStream (ftps) and something like

... SuperStreamWriter ss = new SuperStreamWriter(fs, ms, ftps); ss.Write(helloWorld, 0, helloWorld.length); } class SuperStreamWriter : Stream { Stream[] _s; public SuperStreamWriter(params Stream[] s) { _s = s; } public override void Write(byte[] buffer, int offset, int count) { foreach (Stream s in _s) { s.Write(buffer, offset, count); } } //Other functions cut for example } 

Hello, the world will be crowded out to all three of my streams. Does anyone know anything that will give me similar functionality to what I am describing to others using this foreach loop in a buffer? Also, if the foreach loop is my only / best option, would it be safe to loop through each iteration of the foreach loop, as it is?

+4
source share
1 answer

I don’t know anything about writing to multiple threads at the same time, and in any case, at some point it will be compressed before the loop.

Please note that if you go with the flow with the implementation (which, of course, would be beneficial in terms of performance), keep in mind that the default implementation Stream.BeginWrite - are classes with simultaneous derivatives which have to implement their own asynchronous logic . FileStream implements its own asynchronous behavior, for example, but MemoryStream does not.

+1
source

Source: https://habr.com/ru/post/1302179/


All Articles