]> sigrok.org Git - libsigrok.git/blobdiff - src/scpi/scpi_tcp.c
scpi: Rephrase buffer resize for free space during SCPI read, add comments
[libsigrok.git] / src / scpi / scpi_tcp.c
index cf01c905cf65f8bfa4745275bbe820e15bbb0edc..a4cb694239d303ca20a5242a13d25c63468b86ed 100644 (file)
@@ -17,6 +17,7 @@
  * along with this program.  If not, see <http://www.gnu.org/licenses/>.
  */
 
+#include <config.h>
 #ifdef _WIN32
 #define _WIN32_WINNT 0x0501
 #include <winsock2.h>
@@ -65,15 +66,15 @@ static int scpi_tcp_dev_inst_new(void *priv, struct drv_context *drvc,
        }
 
        tcp->address = g_strdup(params[1]);
-       tcp->port    = g_strdup(params[2]);
-       tcp->socket  = -1;
+       tcp->port = g_strdup(params[2]);
+       tcp->socket = -1;
 
        return SR_OK;
 }
 
-static int scpi_tcp_open(void *priv)
+static int scpi_tcp_open(struct sr_scpi_dev_inst *scpi)
 {
-       struct scpi_tcp *tcp = priv;
+       struct scpi_tcp *tcp = scpi->priv;
        struct addrinfo hints;
        struct addrinfo *results, *res;
        int err;
@@ -86,7 +87,7 @@ static int scpi_tcp_open(void *priv)
        err = getaddrinfo(tcp->address, tcp->port, &hints, &results);
 
        if (err) {
-               sr_err("Address lookup failed: %s:%d: %s", tcp->address, tcp->port,
+               sr_err("Address lookup failed: %s:%s: %s", tcp->address, tcp->port,
                        gai_strerror(err));
                return SR_ERR;
        }
@@ -134,12 +135,9 @@ static int scpi_tcp_send(void *priv, const char *command)
 {
        struct scpi_tcp *tcp = priv;
        int len, out;
-       char *terminated_command;
 
-       terminated_command = g_strdup_printf("%s\r\n", command);
-       len = strlen(terminated_command);
-       out = send(tcp->socket, terminated_command, len, 0);
-       g_free(terminated_command);
+       len = strlen(command);
+       out = send(tcp->socket, command, len, 0);
 
        if (out < 0) {
                sr_err("Send error: %s", g_strerror(errno));
@@ -229,9 +227,9 @@ static int scpi_tcp_read_complete(void *priv)
                        tcp->response_bytes_read >= tcp->response_length);
 }
 
-static int scpi_tcp_close(void *priv)
+static int scpi_tcp_close(struct sr_scpi_dev_inst *scpi)
 {
-       struct scpi_tcp *tcp = priv;
+       struct scpi_tcp *tcp = scpi->priv;
 
        if (close(tcp->socket) < 0)
                return SR_ERR;