Struct sip2::Connection

source ·
pub struct Connection { /* private fields */ }
Expand description

Manages a TCP connection to a SIP server and handles message sending and receiving.

Implementations§

source§

impl Connection

source

pub fn new(sip_host: &str) -> Result<Self, Error>

Creates a new SIP client and opens the TCP connection to the server

  • sip_host - SIP server host/ip and port
  • E.g. “127.0.0.1:6001”
use sip2::Connection;
assert_eq!(Connection::new("JUNK0+..-*z$@").is_err(), true);
source

pub fn from_stream(tcp_stream: TcpStream) -> Self

Create a new SIP connection from an existing TCP stream.

source

pub fn set_log_prefix(&mut self, prefix: impl Into<String>)

Add a string that will be prepended to all log:: calls where a self exists.

source

pub fn set_ascii(&mut self, ascii: bool)

Set the ascii flag

source

pub fn disconnect(&self) -> Result<(), Error>

Shutdown the TCP connection with the SIP server.

source

pub fn send(&mut self, msg: &Message) -> Result<(), Error>

Send a SIP message

source

pub fn send_with_timeout( &mut self, msg: &Message, timeout: u64, ) -> Result<(), Error>

Send a message with a write timeout.

Returns Err() if the send/write times out. Clears the TCP socket timeout upon completion.

source

pub fn recv(&mut self) -> Result<Message, Error>

Receive a SIP response.

Blocks until a response is received.

source

pub fn recv_with_timeout( &mut self, timeout: u64, ) -> Result<Option<Message>, Error>

Receive a message, waiting at most timeout seconds. Clears the TCP socket timeout upon completion.

source

pub fn sendrecv(&mut self, msg: &Message) -> Result<Message, Error>

Shortcut for: self.send(msg); resp = self.recv();

Trait Implementations§

source§

impl Display for Connection

source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more

Auto Trait Implementations§

Blanket Implementations§

source§

impl<T> Any for T
where T: 'static + ?Sized,

source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
source§

impl<T> Borrow<T> for T
where T: ?Sized,

source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
source§

impl<T> From<T> for T

source§

fn from(t: T) -> T

Returns the argument unchanged.

source§

impl<T, U> Into<U> for T
where U: From<T>,

source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

source§

impl<T> ToString for T
where T: Display + ?Sized,

source§

default fn to_string(&self) -> String

Converts the given value to a String. Read more
source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

source§

type Error = Infallible

The type returned in the event of a conversion error.
source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.