summaryrefslogtreecommitdiff
path: root/backend/xerox_mfp-tcp.c
diff options
context:
space:
mode:
authorJörg Frings-Fürst <debian@jff-webhosting.net>2017-05-24 21:03:56 +0200
committerJörg Frings-Fürst <debian@jff-webhosting.net>2017-05-24 21:03:56 +0200
commit58912f68c2489bcee787599837447e0d64dfd61a (patch)
treedda50aadde35fe152da1a8d50769987ace0f1496 /backend/xerox_mfp-tcp.c
parentcfd27ef2ad8b005fd47ab41ef29b71d9e3d48201 (diff)
New upstream version 1.0.27upstream/1.0.27
Diffstat (limited to 'backend/xerox_mfp-tcp.c')
-rw-r--r--backend/xerox_mfp-tcp.c132
1 files changed, 66 insertions, 66 deletions
diff --git a/backend/xerox_mfp-tcp.c b/backend/xerox_mfp-tcp.c
index 2addb0d..845ab7e 100644
--- a/backend/xerox_mfp-tcp.c
+++ b/backend/xerox_mfp-tcp.c
@@ -47,9 +47,9 @@
#define RECV_TIMEOUT 1 /* seconds */
extern int sanei_debug_xerox_mfp;
-int tcp_dev_request (struct device *dev,
- SANE_Byte *cmd, size_t cmdlen,
- SANE_Byte *resp, size_t *resplen)
+int tcp_dev_request(struct device *dev,
+ SANE_Byte *cmd, size_t cmdlen,
+ SANE_Byte *resp, size_t *resplen)
{
size_t bytes_recv = 0;
ssize_t rc = 1;
@@ -58,46 +58,46 @@ int tcp_dev_request (struct device *dev,
/* Send request, if any */
if (cmd && cmdlen) {
- len = (size_t)sanei_tcp_write(dev->dn, cmd, cmdlen);
- if (len != cmdlen) {
- DBG (1, "%s: sent only %lu bytes of %lu\n",
- __FUNCTION__, (u_long)len, (u_long)cmdlen);
- return SANE_STATUS_IO_ERROR;
- }
+ len = (size_t)sanei_tcp_write(dev->dn, cmd, cmdlen);
+ if (len != cmdlen) {
+ DBG(1, "%s: sent only %lu bytes of %lu\n",
+ __func__, (u_long)len, (u_long)cmdlen);
+ return SANE_STATUS_IO_ERROR;
+ }
}
/* Receive response, if expected */
if (resp && resplen) {
- DBG (3, "%s: wait for %i bytes\n", __FUNCTION__, (int)*resplen);
-
- while (bytes_recv < *resplen && rc > 0) {
- rc = recv(dev->dn, resp+bytes_recv, *resplen-bytes_recv, 0);
-
- if (rc > 0) bytes_recv += rc;
- else {
- DBG(1, "%s: error %s, bytes requested: %i, bytes read: %i\n",
- __FUNCTION__, strerror(errno), (int)*resplen, (int)bytes_recv);
- *resplen = bytes_recv;
-/*
- TODO:
- do something smarter than that!
-*/
- return SANE_STATUS_GOOD;
- return SANE_STATUS_IO_ERROR;
- }
- }
+ DBG(3, "%s: wait for %i bytes\n", __func__, (int)*resplen);
+
+ while (bytes_recv < *resplen && rc > 0) {
+ rc = recv(dev->dn, resp+bytes_recv, *resplen-bytes_recv, 0);
+
+ if (rc > 0) bytes_recv += rc;
+ else {
+ DBG(1, "%s: error %s, bytes requested: %i, bytes read: %i\n",
+ __func__, strerror(errno), (int)*resplen, (int)bytes_recv);
+ *resplen = bytes_recv;
+ /*
+ TODO:
+ do something smarter than that!
+ */
+ return SANE_STATUS_GOOD;
+ return SANE_STATUS_IO_ERROR;
+ }
+ }
}
*resplen = bytes_recv;
- return SANE_STATUS_GOOD;
+ return SANE_STATUS_GOOD;
}
-SANE_Status tcp_dev_open (struct device *dev)
+SANE_Status tcp_dev_open(struct device *dev)
{
SANE_Status status;
- char* strhost;
- char* strport;
+ char *strhost;
+ char *strport;
int port;
struct servent *sp;
struct timeval tv;
@@ -105,60 +105,60 @@ SANE_Status tcp_dev_open (struct device *dev)
devname = dev->sane.name;
- DBG (3, "%s: open %s\n", __FUNCTION__, devname);
+ DBG(3, "%s: open %s\n", __func__, devname);
- if (strncmp (devname, "tcp", 3) != 0) return SANE_STATUS_INVAL;
+ if (strncmp(devname, "tcp", 3) != 0) return SANE_STATUS_INVAL;
devname += 3;
- devname = sanei_config_skip_whitespace (devname);
+ devname = sanei_config_skip_whitespace(devname);
if (!*devname) return SANE_STATUS_INVAL;
- devname = sanei_config_get_string (devname, &strhost);
- devname = sanei_config_skip_whitespace (devname);
+ devname = sanei_config_get_string(devname, &strhost);
+ devname = sanei_config_skip_whitespace(devname);
if (*devname)
- devname = sanei_config_get_string (devname, &strport);
+ devname = sanei_config_get_string(devname, &strport);
else
- strport = "9400";
+ strport = "9400";
if (isdigit(*strport)) {
- port = atoi(strport);
+ port = atoi(strport);
} else {
- if ((sp = getservbyname(strport, "tcp"))) {
- port = ntohs(sp->s_port);
- } else {
- DBG (1, "%s: unknown TCP service %s\n", __FUNCTION__, strport);
- return SANE_STATUS_IO_ERROR;
- }
+ if ((sp = getservbyname(strport, "tcp"))) {
+ port = ntohs(sp->s_port);
+ } else {
+ DBG(1, "%s: unknown TCP service %s\n", __func__, strport);
+ return SANE_STATUS_IO_ERROR;
+ }
}
status = sanei_tcp_open(strhost, port, &dev->dn);
if (status == SANE_STATUS_GOOD) {
- tv.tv_sec = RECV_TIMEOUT;
- tv.tv_usec = 0;
- if (setsockopt (dev->dn, SOL_SOCKET, SO_RCVTIMEO, (char *)&tv, sizeof tv) < 0) {
- DBG(1, "%s: setsockopts %s", __FUNCTION__, strerror(errno));
- }
+ tv.tv_sec = RECV_TIMEOUT;
+ tv.tv_usec = 0;
+ if (setsockopt(dev->dn, SOL_SOCKET, SO_RCVTIMEO, (char *)&tv, sizeof tv) < 0) {
+ DBG(1, "%s: setsockopts %s", __func__, strerror(errno));
+ }
}
return status;
}
void
-tcp_dev_close (struct device *dev)
+tcp_dev_close(struct device *dev)
{
if (!dev) return;
- DBG (3, "%s: closing dev %p\n", __FUNCTION__, (void *)dev);
+ DBG(3, "%s: closing dev %p\n", __func__, (void *)dev);
/* finish all operations */
if (dev->scanning) {
- dev->cancel = 1;
- /* flush READ_IMAGE data */
- if (dev->reading) sane_read(dev, NULL, 1, NULL);
- /* send cancel if not sent before */
- if (dev->state != SANE_STATUS_CANCELLED)
- ret_cancel(dev, 0);
+ dev->cancel = 1;
+ /* flush READ_IMAGE data */
+ if (dev->reading) sane_read(dev, NULL, 1, NULL);
+ /* send cancel if not sent before */
+ if (dev->state != SANE_STATUS_CANCELLED)
+ ret_cancel(dev, 0);
}
sanei_tcp_close(dev->dn);
@@ -167,15 +167,15 @@ tcp_dev_close (struct device *dev)
SANE_Status
-tcp_configure_device (const char *devname, SANE_Status (*list_one)(SANE_String_Const devname))
+tcp_configure_device(const char *devname, SANE_Status(*list_one)(SANE_String_Const devname))
{
-/*
- TODO: LAN scanners multicast discovery.
- devname would contain "tcp auto"
-
- We find new devnames and feed them to
- `list_one_device' one by one
-*/
+ /*
+ TODO: LAN scanners multicast discovery.
+ devname would contain "tcp auto"
+
+ We find new devnames and feed them to
+ `list_one_device' one by one
+ */
return list_one(devname);
}