private void SendCallback(IAsyncResult result) { DataSendContext cx = null; try { cx = (DataSendContext)result.AsyncState; Stream.EndWrite(result); if (cx.DataRemained == true) { cx.FillBuffer(); this.Stream.BeginWrite(cx.GetByteArray(), 0, cx.SendBufferSize, this.SendCallback, cx); } else { this.SendDone.Set(); } } catch (Exception ex) { cx.Exception = ex; } if (cx.Exception != null) { try { //タイミングの問題でDisposeされている場合がある this.SendDone.Set(); } catch (ObjectDisposedException) { } } }
/// <summary> /// /// </summary> /// <param name="stream"></param> public void Send(Stream stream) { DataSendContext cx = null; if (this.Socket == null) { throw new SocketClientException("Connection is closed"); } try { cx = new DataSendContext(stream, Encoding.ASCII); cx.FillBuffer(); this.Stream.BeginWrite(cx.GetByteArray(), 0, cx.SendBufferSize, this.SendCallback, cx); this.SendDone.WaitOne(); } catch (Exception ex) { throw new SocketClientException(ex); } finally { if (cx != null) { cx.Dispose(); } } //Throw exception that occor other thread. if (cx.Exception != null) { throw cx.Exception; } }
private void SendCallback(IAsyncResult result) //Nustato SendDone event kai nusiunciamas visas bufferis { DataSendContext cx = null; //+ try { cx = (DataSendContext)result.AsyncState; //+ Stream.EndWrite(result); //+ if (cx.DataRemained == true) //+ { cx.FillBuffer(); //Nuskaitom bb.lenght baitu is streamo arba tiek kiek liko this.Stream.BeginWrite(cx.GetByteArray(), 0, cx.SendBufferSize, this.SendCallback, cx); //+ } else { this.SendDone.Set(); //+ } } catch (Exception ex) { cx.Exception = ex; } if (cx.Exception != null) { try { this.SendDone.Set(); } catch (ObjectDisposedException) { } } }
public void Send(Stream stream) //Nusiunciamas duomenu buferis duotu streamu { DataSendContext cx = null; //Duomenys apie siuntimui naudojama streama, bufferio didi ir informacija apie duomenys if (this.Socket == null) { throw new SocketClientException("Connection is closed"); //Jei socketas uzdaritas } try { cx = new DataSendContext(stream, Encoding.ASCII); //Uzpildomas DataTransferContext bufferis, nustatomas encoding, streamas ir bufferio didis cx.FillBuffer(); //Nuskaitom bb.lenght baitu is streamo arba tiek kiek liko this.Stream.BeginWrite(cx.GetByteArray(), 0, cx.SendBufferSize, this.SendCallback, cx); //Siuncia bufferi streamu this.SendDone.WaitOne(); //Laukia kol bus nusiustas visas bufferis } catch (Exception ex) { throw new SocketClientException(ex); //Error siunciant bufferi } finally { if (cx != null) { cx.Dispose(); //Istrinam Datasendcontext, nes daug vietos uzeme su buffereis } } //Throw exception that occor other thread. if (cx.Exception != null) { throw cx.Exception; //Jei ivyko kitas exception cx viduje } }
/// <summary> /// /// </summary> /// <param name="stream"></param> public void Send(Stream stream) { DataSendContext cx = null; if (this.Socket == null) { throw new SocketClientException("Connection is closed"); } try { cx = new DataSendContext(stream, this.RequestEncoding); cx.FillBuffer(); this.Stream.BeginWrite(cx.Buffer, 0, cx.SendBufferSize, this.SendCallback, cx); this.SendDone.WaitOne(); if (TraceSource.Listeners.Count > 0) { TraceSource.TraceInformation(String.Format("{0} Client Send:{1}", DateTime.Now.ToString("yyyy/MM/dd HH:mm:ss.fffffff"), cx.GetText())); } } catch (Exception ex) { throw new SocketClientException(ex); } finally { if (cx != null) { cx.Dispose(); } } //Throw exception that occor other thread. if (cx.Exception != null) { throw cx.Exception; } }