Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
22 changes: 17 additions & 5 deletions mgmt/utils/MgmtSocket.cc
Original file line number Diff line number Diff line change
Expand Up @@ -42,15 +42,27 @@
bool
mgmt_transient_error()
{
bool transient = false;
transient = (errno == EINTR);
switch (errno) {
case EINTR:
case EAGAIN:

#ifdef ENOMEM
transient = transient || (errno == ENOMEM);
case ENOMEM:
#endif

#ifdef ENOBUF
transient = transient || (errno == ENOBUF);
case ENOBUF:
#endif

#if defined(EWOULDBLOCK) && (EWOULDBLOCK != EAGAIN)
case EWOULDBLOCK:
#endif
return transient;

return true;

default:
return false;
}
}

//-------------------------------------------------------------------------
Expand Down
57 changes: 32 additions & 25 deletions mgmt/utils/MgmtUtils.cc
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@
#include "ts/ink_platform.h"
#include "ts/ink_sock.h"
#include "MgmtUtils.h"
#include "MgmtSocket.h"
#include "ts/Diags.h"

#include "LocalManager.h"
Expand Down Expand Up @@ -52,11 +53,12 @@ mgmt_use_syslog()
int
mgmt_readline(int soc, char *buf, int maxlen)
{
int n, rc;
int n = 0, rc;
char c;

for (n = 1; n < maxlen; n++) {
if ((rc = read_socket(soc, &c, 1)) == 1) {
for (; n < maxlen; n++) {
rc = read_socket(soc, &c, 1);
if (rc == 1) {
*buf++ = c;
if (c == '\n') {
--buf;
Expand All @@ -74,9 +76,19 @@ mgmt_readline(int soc, char *buf, int maxlen)
break;
}
} else { /* Error */
if (errno == ECONNRESET || errno == EPIPE) {
return n ? n : 0;
}

if (mgmt_transient_error()) {
mgmt_sleep_msec(1);
continue;
}

return -1;
}
}

return n;
} /* End mgmt_readline */

Expand Down Expand Up @@ -132,30 +144,30 @@ mgmt_read_pipe(int fd, char *buf, int bytes_to_read)
int err = 0;
char *p = buf;
int bytes_read = 0;

while (bytes_to_read > 0) {
err = read_socket(fd, p, bytes_to_read);
if (err == 0) {
return err;
} else if (err < 0) {
switch (errno) {
case EINTR:
case EAGAIN:
#if defined(hpux)
case EWOULDBLOCK:
#endif
// Turn ECONNRESET into EOF.
if (errno == ECONNRESET || errno == EPIPE) {
return bytes_read ? bytes_read : 0;
}

if (mgmt_transient_error()) {
mgmt_sleep_msec(1);
continue;
default:
return -errno;
}

return -errno;
}

bytes_to_read -= err;
bytes_read += err;
p += err;
}
/*
Ldone:
*/

return bytes_read;
}

Expand All @@ -174,30 +186,25 @@ mgmt_write_pipe(int fd, char *buf, int bytes_to_write)
int err = 0;
char *p = buf;
int bytes_written = 0;

while (bytes_to_write > 0) {
err = write_socket(fd, p, bytes_to_write);
if (err == 0) {
return err;
} else if (err < 0) {
switch (errno) {
case EINTR:
case EAGAIN:
#if defined(hpux)
case EWOULDBLOCK:
#endif
if (mgmt_transient_error()) {
mgmt_sleep_msec(1);
continue;
default:
return -errno;
}

return -errno;
}

bytes_to_write -= err;
bytes_written += err;
p += err;
}
/*
Ldone:
*/

return bytes_written;
}

Expand Down