From: <enl...@li...> - 2002-07-30 21:36:33
|
Enlightenment CVS committal Author : mej Project : eterm Module : libast Dir : eterm/libast/src Modified Files: socket.c str.c Log Message: Tue Jul 30 17:34:38 2002 Michael Jennings (mej) Send/receive on the socket works now. Also cleaned up the show method for strings to eliminate the 4K length limit. The current socket test will actually download the HTML for my home page. Uncomment the SPIF_SHOW() call in test_socket() to see it work. =================================================================== RCS file: /cvsroot/enlightenment/eterm/libast/src/socket.c,v retrieving revision 1.6 retrieving revision 1.7 diff -u -3 -r1.6 -r1.7 --- socket.c 26 Jul 2002 20:57:39 -0000 1.6 +++ socket.c 30 Jul 2002 21:36:03 -0000 1.7 @@ -21,7 +21,7 @@ * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. */ -static const char cvs_ident[] = "$Id: socket.c,v 1.6 2002/07/26 20:57:39 mej Exp $"; +static const char cvs_ident[] = "$Id: socket.c,v 1.7 2002/07/30 21:36:03 mej Exp $"; #ifdef HAVE_CONFIG_H # include <config.h> @@ -91,8 +91,6 @@ self->flags = 0; self->src_url = SPIF_NULL_TYPE(url); self->dest_url = SPIF_NULL_TYPE(url); - self->input = SPIF_NULL_TYPE(str); - self->output = SPIF_NULL_TYPE(str); return TRUE; } @@ -118,8 +116,6 @@ } else { self->dest_url = SPIF_NULL_TYPE(url); } - self->input = SPIF_NULL_TYPE(str); - self->output = SPIF_NULL_TYPE(str); return TRUE; } @@ -127,10 +123,7 @@ spif_socket_done(spif_socket_t self) { if (self->fd >= 0) { - if ((close(self->fd)) < 0) { - print_error("Unable to close socket %d -- %s\n", self->fd, strerror(errno)); - } - self->fd = -1; + spif_socket_close(self); } self->fam = AF_INET; self->type = SOCK_STREAM; @@ -149,14 +142,6 @@ spif_url_del(self->dest_url); self->dest_url = SPIF_NULL_TYPE(url); } - if (!SPIF_STR_ISNULL(self->input)) { - spif_str_del(self->input); - self->input = SPIF_NULL_TYPE(str); - } - if (!SPIF_STR_ISNULL(self->output)) { - spif_str_del(self->output); - self->output = SPIF_NULL_TYPE(str); - } return TRUE; } @@ -203,8 +188,6 @@ spif_url_show(self->src_url, "src_url", buff, indent); spif_url_show(self->dest_url, "dest_url", buff, indent); - spif_str_show(self->input, "input", buff, indent); - spif_str_show(self->output, "output", buff, indent); indent -= 2; snprintf(tmp + indent, sizeof(tmp) - indent, "}\n"); @@ -243,8 +226,6 @@ if (!SPIF_URL_ISNULL(self->dest_url)) { tmp->dest_url = spif_url_dup(self->dest_url); } - tmp->input = SPIF_NULL_TYPE(str); - tmp->output = SPIF_NULL_TYPE(str); return tmp; } @@ -337,6 +318,24 @@ } spif_bool_t +spif_socket_close(spif_socket_t self) +{ + int ret; + + REQUIRE_RVAL(self->fd >= 0, FALSE); + do { + ret = close(self->fd); + } while ((ret < 0) && (errno == EINTR)); + if (ret < 0) { + print_error("Unable to close socket %d -- %s\n", self->fd, strerror(errno)); + self->fd = -1; + return FALSE; + } + self->fd = -1; + return TRUE; +} + +spif_bool_t spif_socket_check_io(spif_socket_t self) { static struct timeval tv = { 0, 0 }; @@ -393,34 +392,33 @@ if (num_written < 0) { D_OBJ(("Unable to write to socket %d -- %s\n", self->fd, strerror(errno))); switch (errno) { - case EFBIG: - { - spif_bool_t b; - spif_str_t tmp_buf; - char *s; - long left; - - for (left = len, s = SPIF_STR_STR(data); left > 0; s += 1024, left -= 1024) { - tmp_buf = spif_str_new_from_buff(s, 1024); - b = spif_socket_send(self, tmp_buf); - if (b == FALSE) { - spif_str_del(tmp_buf); - return b; + case EFBIG: + { + spif_bool_t b; + spif_str_t tmp_buf; + char *s; + long left; + + for (left = len, s = SPIF_STR_STR(data); left > 0; s += 1024, left -= 1024) { + tmp_buf = spif_str_new_from_buff(s, 1024); + b = spif_socket_send(self, tmp_buf); + if (b == FALSE) { + spif_str_del(tmp_buf); + return b; + } } } - } - break; - case EIO: - case EPIPE: - close(self->fd); - /* Drop */ - case EBADF: - case EINVAL: - default: - self->fd = -1; - return FALSE; - break; - + break; + case EIO: + case EPIPE: + close(self->fd); + /* Drop */ + case EBADF: + case EINVAL: + default: + self->fd = -1; + return FALSE; + break; } } return TRUE; @@ -429,7 +427,10 @@ spif_str_t spif_socket_recv(spif_socket_t self) { + spif_str_t new_str; + new_str = spif_str_new_from_fd(self->fd); + return new_str; } spif_bool_t =================================================================== RCS file: /cvsroot/enlightenment/eterm/libast/src/str.c,v retrieving revision 1.14 retrieving revision 1.15 diff -u -3 -r1.14 -r1.15 --- str.c 26 Jul 2002 04:17:18 -0000 1.14 +++ str.c 30 Jul 2002 21:36:03 -0000 1.15 @@ -21,7 +21,7 @@ * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. */ -static const char cvs_ident[] = "$Id: str.c,v 1.14 2002/07/26 04:17:18 mej Exp $"; +static const char cvs_ident[] = "$Id: str.c,v 1.15 2002/07/30 21:36:03 mej Exp $"; #ifdef HAVE_CONFIG_H # include <config.h> @@ -505,14 +505,18 @@ } memset(tmp, ' ', indent); - snprintf(tmp + indent, sizeof(tmp) - indent, "(spif_str_t) %s: %8p { \"%s\", len %lu, size %lu }\n", - name, self, self->s, (unsigned long) self->len, (unsigned long) self->mem); - + snprintf(tmp + indent, sizeof(tmp) - indent, "(spif_str_t) %s: %8p { \"", name, self); if (SPIF_STR_ISNULL(buff)) { buff = spif_str_new_from_ptr(tmp); } else { spif_str_append_from_ptr(buff, tmp); } + + spif_str_append(buff, self); + + snprintf(tmp, sizeof(tmp), "\", len %lu, size %lu }\n", (unsigned long) self->len, + (unsigned long) self->mem); + spif_str_append_from_ptr(buff, tmp); return buff; } |