summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorLuo Jinghua <sunmoon1997@gmail.com>2009-09-13 14:04:33 +0800
committerLuo Jinghua <sunmoon1997@gmail.com>2009-09-13 14:04:33 +0800
commit2f58c4dd67115a7159122a169b580c54a0efc8e7 (patch)
treefb241026fb8899b8803b6b33bad2b89e5dc16847
parent7718f3ff1b69f79f468068cffc56dd041cc6c8eb (diff)
sopcastsrc: more logging
-rw-r--r--src/gstscsrc.c39
-rw-r--r--src/gstscsrc.h2
2 files changed, 29 insertions, 12 deletions
diff --git a/src/gstscsrc.c b/src/gstscsrc.c
index 5bbccf2..27e6b94 100644
--- a/src/gstscsrc.c
+++ b/src/gstscsrc.c
@@ -244,9 +244,9 @@ gst_sopcast_src_connect_server (GstSopcastSrc *src)
struct sockaddr_in sockaddr;
int sock;
- if (src->socks[0] >= 0) {
- close (src->socks[0]);
- src->socks[0] = -1;
+ if (src->sock >= 0) {
+ close (src->sock);
+ src->sock = -1;
}
sock = socket (AF_INET, SOCK_STREAM, 0);
@@ -267,7 +267,7 @@ gst_sopcast_src_connect_server (GstSopcastSrc *src)
return FALSE;
}
- src->socks[0] = sock;
+ src->sock = sock;
src->first_request = TRUE;
return TRUE;
}
@@ -287,7 +287,7 @@ gst_sopcast_src_send_first_request (GstSopcastSrc *src)
"Accept: */*\r\n"
"\r\n", src->ports[1]);
- ret = send (src->socks[0], request, strlen (request), 0);
+ ret = send (src->sock, request, strlen (request), 0);
if (ret < 0) {
perror ("Could't sent request to server");
return FALSE;
@@ -295,7 +295,7 @@ gst_sopcast_src_send_first_request (GstSopcastSrc *src)
for (n = 0; n < sizeof (reply) - 1; n++) {
do {
- ret = recv (src->socks[0], &reply[n], 1, 0);
+ ret = recv (src->sock, &reply[n], 1, 0);
} while (ret < 0 && errno == EINTR);
if (ret < 0)
return FALSE;
@@ -518,7 +518,7 @@ gst_sopcast_src_create (GstPushSrc * psrc, GstBuffer ** buffer)
fd_set rfs;
fd_set efs;
struct timeval tv;
- int sock = src->socks[0];
+ int sock = src->sock;
if (src->interrupted /* || !gst_sopcast_src_helper_is_running (src) */)
goto could_not_read;
@@ -744,6 +744,8 @@ gst_sopcast_src_spawn_sopcast (GstSopcastSrc * src)
if (ret < 0)
return FALSE;
+ GST_DEBUG_OBJECT (src, "socketpair() = (%d, %d)", fds[0], fds[1]);
+
ppid = getpid ();
pid = fork ();
if (pid == 0) {
@@ -751,8 +753,11 @@ gst_sopcast_src_spawn_sopcast (GstSopcastSrc * src)
gst_sopcast_src_subproc_main (src, ppid, fds[1]);
} else if (pid > 0) {
close (fds[1]);
+
+ GST_DEBUG_OBJECT (src, "child %d heatebeat fd = %d", pid, fds[0]);
src->heatebeat_fd = fds[0];
src->helper_pid = pid;
+ return TRUE;
} else {
close (fds[0]);
close (fds[1]);
@@ -792,18 +797,30 @@ gst_sopcast_src_stop (GstBaseSrc * bsrc)
{
GstSopcastSrc *src;
int status;
+ int ret;
char buf[12];
src = GST_SOPCAST_SRC (bsrc);
GST_DEBUG_OBJECT (src, "stop()");
- close (src->socks[0]);
- src->socks[0] = -1;
+ close (src->sock);
+ src->sock = -1;
GST_DEBUG_OBJECT (src, "say goodbye to subprocess %d", src->helper_pid);
- send (src->heatebeat_fd, "bye", 3, 0);
- recv (src->heatebeat_fd, buf, 3, 0);
+ GST_DEBUG_OBJECT (src, "heatebeat fd = %d", src->heatebeat_fd);
+ do {
+ errno = 0;
+ ret = send (src->heatebeat_fd, "bye", 3, 0);
+ } while (ret < 0 && errno == EINTR);
+ GST_DEBUG_OBJECT (src, "ret %d %s", ret, strerror (errno));
+
+ do {
+ errno = 0;
+ ret = recv (src->heatebeat_fd, buf, 3, 0);
+ } while (ret < 0 && errno == EINTR);
+ GST_DEBUG_OBJECT (src, "ret %d %s", ret, strerror (errno));
+
close (src->heatebeat_fd);
src->heatebeat_fd = -1;
diff --git a/src/gstscsrc.h b/src/gstscsrc.h
index d3d4022..1feaa6d 100644
--- a/src/gstscsrc.h
+++ b/src/gstscsrc.h
@@ -44,7 +44,7 @@ struct _GstSopcastSrc {
gchar *location; /* Full URI. */
int ports[2]; /* inboud/outbound ports */
- int socks[2]; /**/
+ int sock; /* the socket connected to server */
pid_t helper_pid; /* The pid of helper */
gboolean first_request; /* The first request */
gint percent; /* buffering percentage */