Example #1
0
        public void HandleWrite(IOStream stream)
        {
            while (bytes.Count > 0) {
                int len = -1;
                try {
                    len = stream.socket.Send (bytes);
                } catch (SocketException se) {
                    if (se.SocketErrorCode == SocketError.WouldBlock || se.SocketErrorCode == SocketError.TryAgain)
                        return;
                    stream.Close ();
                } catch (Exception e) {
                    stream.Close ();
                } finally {
                    if (len != -1) {
                        int num_segments = bytes.Count;
                        IOStream.AdjustSegments (len, bytes);
                        segments_written = num_segments - bytes.Count;
                    }
                }
            }

            FireCallbacks ();
            IsComplete = (bytes.Count == 0);
        }
Example #2
0
        public void HandleWrite(IOStream stream)
        {
            while (file_offset < file_length) {
                  try {
                      Mono.Unix.Native.Syscall.sendfile (stream.socket.Handle.ToInt32 (),
                              file.Handle.ToInt32 (), ref file_offset,
                              (ulong) (file_length - file_offset));
                  } catch (SocketException se) {
                      if (se.SocketErrorCode == SocketError.WouldBlock || se.SocketErrorCode == SocketError.TryAgain)
                          return;
                      stream.Close ();
                  } catch (Exception e) {
                      stream.Close ();
                  }
            }

            if (file_offset >= file_length)
                IsComplete = true;
        }
        public void HandleWrite(IOStream stream)
        {
            while (bytes_index < file_length) {
                int len = -1;
                try {
                    len = stream.socket.Send (bytes, bytes_index, file_length, SocketFlags.None);
                } catch (SocketException se) {
                    if (se.SocketErrorCode == SocketError.WouldBlock || se.SocketErrorCode == SocketError.TryAgain)
                        return;
                    stream.Close ();
                } catch (Exception e) {
                    stream.Close ();
                } finally {
                    if (len != -1)
                        bytes_index += len;
                }
            }

            IsComplete = (bytes_index == file_length);
        }