From e38e7495cd18b7756b6c3a216faaacc62a89f2ad Mon Sep 17 00:00:00 2001
From: smorlat <smorlat@3f6dc0c8-ddfe-455d-9043-3cd528dc4637>
Date: Mon, 18 May 2009 21:17:46 +0000
Subject: [PATCH] start implementing a named pipe abstraction.

git-svn-id: svn+ssh://svn.savannah.nongnu.org/linphone/trunk@479 3f6dc0c8-ddfe-455d-9043-3cd528dc4637
---
 linphone/oRTP/include/ortp/port.h | 13 ++++++
 linphone/oRTP/src/port.c          | 74 +++++++++++++++++++++++++++++++
 linphone/oRTP/src/rtpparse.c      |  2 +-
 3 files changed, 88 insertions(+), 1 deletion(-)

diff --git a/linphone/oRTP/include/ortp/port.h b/linphone/oRTP/include/ortp/port.h
index 6b28d33ca2..05b2457309 100644
--- a/linphone/oRTP/include/ortp/port.h
+++ b/linphone/oRTP/include/ortp/port.h
@@ -230,6 +230,19 @@ char *ortp_strndup(const char *str,int n);
 char *ortp_strdup_printf(const char *fmt,...);
 char *ortp_strdup_vprintf(const char *fmt, va_list ap);
 
+/* portable named pipes */
+ortp_socket_t ortp_server_pipe_create(const char *name);
+ortp_socket_t ortp_server_pipe_accept_client(ortp_socket_t server);
+int ortp_server_pipe_close(ortp_socket_t spipe);
+int ortp_server_pipe_close_client(ortp_socket_t client);
+
+ortp_socket_t ortp_client_pipe_connect(const char *name);
+int ortp_client_pipe_close(ortp_socket_t sock);
+
+int ortp_pipe_read(ortp_socket_t p, uint8_t *buf, int len);
+int ortp_pipe_write(ortp_socket_t p, const uint8_t *buf, int len);
+
+
 #ifdef __cplusplus
 }
 #endif
diff --git a/linphone/oRTP/src/port.c b/linphone/oRTP/src/port.c
index 4b42b1c699..470fe30461 100644
--- a/linphone/oRTP/src/port.c
+++ b/linphone/oRTP/src/port.c
@@ -334,3 +334,77 @@ char * WSAAPI gai_strerror(int errnum){
 
 #endif
 
+#ifndef WIN32
+
+#include <sys/socket.h>
+#include <netdb.h>
+#include <sys/un.h>
+#include <sys/stat.h>
+
+/* portable named pipes */
+ortp_socket_t ortp_server_pipe_create(const char *name){
+	struct sockaddr_un sa;
+	ortp_socket_t sock;
+	sock=socket(AF_UNIX,SOCK_STREAM,0);
+	sa.sun_family=AF_UNIX;
+	strncpy(sa.sun_path,name,sizeof(sa.sun_path)-1);
+	unlink(name);/*in case we didn't finished properly previous time */
+	fchmod(sock,S_IRUSR|S_IWUSR);
+	if (bind(sock,(struct sockaddr*)&sa,sizeof(sa))!=0){
+		ortp_error("Failed to bind command unix socket: %s",strerror(errno));
+		return -1;
+	}
+	listen(sock,1);
+	return sock;
+}
+
+ortp_socket_t ortp_server_pipe_accept_client(ortp_socket_t server){
+	struct sockaddr_un su;
+	socklen_t ssize=sizeof(su);
+	ortp_socket_t client_sock=accept(server,(struct sockaddr*)&su,&ssize);
+	return client_sock;
+}
+
+int ortp_server_pipe_close_client(ortp_socket_t client){
+	return close(client);
+}
+
+int ortp_server_pipe_close(ortp_socket_t spipe){
+	return close(spipe);
+}
+
+ortp_socket_t ortp_client_pipe_connect(const char *name){
+	struct sockaddr_un sa;
+	ortp_socket_t sock=socket(AF_UNIX,SOCK_STREAM,0);
+	sa.sun_family=AF_UNIX;
+	strncpy(sa.sun_path,name,sizeof(sa.sun_path)-1);
+	if (connect(sock,(struct sockaddr*)&sa,sizeof(sa))!=0){
+		close(sock);
+		return -1;
+	}
+	return sock;
+}
+
+int ortp_pipe_read(ortp_socket_t p, uint8_t *buf, int len){
+	return read(p,buf,len);
+}
+
+int ortp_pipe_write(ortp_socket_t p, const uint8_t *buf, int len){
+	return write(p,buf,len);
+}
+
+int ortp_client_pipe_close(ortp_socket_t sock){
+	return close(sock);
+}
+
+#else
+/* portable named pipes */
+ortp_socket_t ortp_server_pipe_create(const char *name);
+ortp_socket_t ortp_server_pipe_accept(ortp_socket_t server);
+int ortp_server_pipe_close(ortp_socket_t spipe);
+
+ortp_socket_t ortp_call_pipe(const char *name);
+
+int ortp_pipe_read(ortp_socket_t p, uint8_t *buf, int len);
+int ortp_pipe_write(ortp_socket_t p, const uint8_t *buf, int len);
+#endif
diff --git a/linphone/oRTP/src/rtpparse.c b/linphone/oRTP/src/rtpparse.c
index 1356c7e557..9a15ab9db9 100644
--- a/linphone/oRTP/src/rtpparse.c
+++ b/linphone/oRTP/src/rtpparse.c
@@ -145,7 +145,7 @@ void rtp_session_rtp_parse(RtpSession *session, mblk_t *mp, uint32_t local_str_t
 						session->rtp.rem_addrlen=addrlen;
 					}
 				}
-
+				session->rtp.rcv_last_ts = rtp->timestamp;
 				session->rcv.ssrc=rtp->ssrc;
 				rtp_signal_table_emit(&session->on_ssrc_changed);
 			}else{
-- 
GitLab