From: Ramakrishnan Muthukrishnan Date: Thu, 10 Aug 2023 09:15:14 +0000 (+0530) Subject: rustify send_resp() in rigctl.c X-Git-Url: https://git.rkrishnan.org/components/com_hotproperty/css/%22file:/%5B%5E?a=commitdiff_plain;h=refs%2Fheads%2Frust-new;p=pihpsdr.git rustify send_resp() in rigctl.c --- diff --git a/rigctl.c b/rigctl.c index 6024661..10dde25 100644 --- a/rigctl.c +++ b/rigctl.c @@ -59,6 +59,8 @@ #endif #include +#include "libhpsdr.h" + #define NEW_PARSER // IP stuff below @@ -661,19 +663,6 @@ long long rigctl_getFrequency() { return vfo[active_receiver->id].frequency; } } -// Looks up entry INDEX_NUM in the command structure and -// returns the command string -// -void send_resp(int fd, char *msg) { - if (rigctl_debug) - g_print("RIGCTL: RESP=%s\n", msg); - int length = strlen(msg); - int written = 0; - - while (written < length) { - written += write(fd, &msg[written], length - written); - } -} // // 2-25-17 - K5JAE - removed duplicate rigctl @@ -770,7 +759,7 @@ static gpointer rigctl_client(gpointer data) { g_mutex_lock(&mutex_a->m); cat_control++; if (rigctl_debug) - g_print("RIGCTL: CTLA INC cat_contro=%d\n", cat_control); + g_print("RIGCTL: CTLA INC cat_control=%d\n", cat_control); g_mutex_unlock(&mutex_a->m); g_idle_add(ext_vfo_update, NULL); diff --git a/rust/src/rigctl.rs b/rust/src/rigctl.rs index 8aea534..5832cfc 100644 --- a/rust/src/rigctl.rs +++ b/rust/src/rigctl.rs @@ -1,4 +1,4 @@ -use std::os::fd::FromRawFd; +use std::os::fd::{FromRawFd, IntoRawFd}; use std::{fs::File, io::Write}; use std::slice; use libc::{write, c_int, c_char}; @@ -8,6 +8,8 @@ pub extern "C" fn send_resp(fd: c_int, msg: *const c_char) -> () { let mut f: File = unsafe { File::from_raw_fd(fd) }; let cstr = unsafe { std::ffi::CStr::from_ptr(msg) }; let buf: &[u8] = cstr.to_bytes(); + println!("send_resp: {}", std::str::from_utf8(buf).unwrap()); let _ = f.write_all(buf); + let _ = f.into_raw_fd(); // this is so that fd is not closed () }