Skip to content

Commit

Permalink
removed dependency on SinkExt crate
Browse files Browse the repository at this point in the history
  • Loading branch information
KaranGauswami committed Sep 16, 2023
1 parent 12e4f79 commit b206f0e
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 8 deletions.
1 change: 0 additions & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,6 @@ tracing = "0.1"
bytes = "1.4"
tokio-util = { version = "0.7", features = ["codec"] }
tokio-stream = "0.1"
futures = "0.3"
serde_json = "1.0"
uuid = { version = "1.4", features = ["v4"] }
thiserror = "1.0"
Expand Down
18 changes: 11 additions & 7 deletions src/connection.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,26 +3,25 @@ use crate::error::EslError;
use crate::esl::EslConnectionType;
use crate::event::Event;
use crate::io::EslCodec;
use futures::SinkExt;
use serde_json::Value;
use std::collections::{HashMap, VecDeque};
use std::sync::atomic::Ordering;
use std::sync::{atomic::AtomicBool, Arc};
use tokio::io::WriteHalf;
use tokio::io::{AsyncWriteExt, WriteHalf};
use tokio::net::TcpStream;
use tokio::sync::{
oneshot::{channel, Sender},
Mutex,
};
use tokio_stream::StreamExt;
use tokio_util::codec::{FramedRead, FramedWrite};
use tracing::trace;
use tokio_util::codec::FramedRead;
use tracing::{error, trace};
#[derive(Debug)]
/// contains Esl connection with freeswitch
pub struct EslConnection {
password: String,
commands: Arc<Mutex<VecDeque<Sender<Event>>>>,
transport_tx: Arc<Mutex<FramedWrite<WriteHalf<TcpStream>, EslCodec>>>,
transport_tx: Arc<Mutex<WriteHalf<TcpStream>>>,
background_jobs: Arc<Mutex<HashMap<String, Sender<Event>>>>,
connected: AtomicBool,
pub(crate) call_uuid: Option<String>,
Expand All @@ -46,7 +45,12 @@ impl EslConnection {
}
pub(crate) async fn send(&self, item: &[u8]) -> Result<(), EslError> {
let mut transport = self.transport_tx.lock().await;
transport.send(item).await
let error = transport.write_all(item).await;
error!("Error writing data into TCP stream {:?}", error);
// TODO: fix this write
let error = transport.write_all(b"\n\n").await;
error!("Error writing data into TCP stream {:?}", error);
Ok(())
}
/// sends raw message to freeswitch and receives reply
pub async fn send_recv(&self, item: &[u8]) -> Result<Event, EslError> {
Expand All @@ -69,7 +73,7 @@ impl EslConnection {
let esl_codec = EslCodec {};
let (read_half, write_half) = tokio::io::split(stream);
let mut transport_rx = FramedRead::new(read_half, esl_codec.clone());
let transport_tx = Arc::new(Mutex::new(FramedWrite::new(write_half, esl_codec.clone())));
let transport_tx = Arc::new(Mutex::new(write_half));
if connection_type == EslConnectionType::Inbound {
transport_rx.next().await;
}
Expand Down

0 comments on commit b206f0e

Please sign in to comment.