public void Send(SipMessage message) { using (TimedLock.Lock(transport)) { if (sendPending) { sendQueue.Enqueue(message); return; } try { var packet = message.ToArray(); sock.BeginSendAll(packet, 0, packet.Length, SocketFlags.None, onSend, null); sendPending = true; } catch (SocketException) { CloseAndRemove(); } catch (Exception e) { SysLog.LogException(e); } } }
/// <summary> /// Asynchronously transmits the message passed to the destination /// indicated by the <see paramref="remoteEP" /> parameter. /// </summary> /// <param name="remoteEP">The destination SIP endpoint's <see cref="NetworkBinding" />.</param> /// <param name="message">The <see cref="SipMessage" /> to be transmitted.</param> /// <exception cref="SipTransportException">Thrown if the remote endpoint rejected the message or timed out.</exception> public void Send(NetworkBinding remoteEP, SipMessage message) { if (disabled) { return; } if ((traceMode & SipTraceMode.Send) != 0) { SipHelper.Trace(string.Format("UDP: sending to {0}", remoteEP), message); } try { sock.SendTo(message.ToArray(), remoteEP); } catch (SocketException e) { // $todo(jeff.lill): // // This is just copied from the TCP transport. It probably // doesn't apply here. switch ((SocketError)e.ErrorCode) { case SocketError.ConnectionAborted: case SocketError.ConnectionRefused: case SocketError.ConnectionReset: case SocketError.HostDown: case SocketError.HostNotFound: case SocketError.HostUnreachable: throw new SipTransportException(SipTransportException.ErrorType.Rejected, e.Message, e); case SocketError.TimedOut: throw new SipTransportException(SipTransportException.ErrorType.Timeout, e.Message, e); default: throw; } } }