#using UDS socket
#CPPFLAGS="${CPPFLAGS} -D_USE_UDS_SOCKET_"
+CPPFLAGS="${CPPFLAGS} -D_USE_UDS_SOCKET_TCP_"
# FMS_DEBUG - File Manager Service debug options
# To open debug options:
#define MS_SCAN_COMM_PORT 1008 /**< Port of communication between scanner and server */
#endif
+#ifdef _USE_UDS_SOCKET_TCP_
+typedef enum{
+ MS_DB_BATCH_UPDATE_TCP_PORT = 0, /**< Media DB batch update */
+ MS_THUMB_CREATOR_TCP_PORT, /**< Create thumbnail */
+ MS_PORT_MAX,
+}ms_msg_port_type_e;
+#endif
+
#define MAX_MSG_SIZE 4096
typedef enum{
#else
#include <sys/socket.h>
#endif
+
+#ifdef _USE_UDS_SOCKET_TCP_
+#include <sys/un.h>
+#endif
+
#include <netinet/in.h>
#include <arpa/inet.h>
#else
int ms_ipc_create_client_socket(ms_protocol_e protocol, int timeout_sec, int *sock_fd);
#endif
+
+#ifdef _USE_UDS_SOCKET_TCP_
+int ms_ipc_create_client_tcp_socket(ms_protocol_e protocol, int timeout_sec, int *sock_fd, int port);
+int ms_ipc_create_server_tcp_socket(ms_protocol_e protocol, int port, int *sock_fd);
+#endif
+
int ms_ipc_create_server_socket(ms_protocol_e protocol, int port, int *sock_fd);
#ifdef _USE_UDS_SOCKET_
int ms_ipc_send_msg_to_server(int sockfd, int port, ms_comm_msg_s *send_msg, struct sockaddr_un *serv_addr);
#ifdef _USE_UDS_SOCKET_
extern char MEDIA_IPC_PATH[][50];
+#elif defined(_USE_UDS_SOCKET_TCP_)
+extern char MEDIA_IPC_PATH[][50];
#endif
+
static int __media_db_prepare_tcp_client_socket()
{
int ret = MS_MEDIA_ERR_NONE;
int sockfd = -1;
#ifdef _USE_UDS_SOCKET_
struct sockaddr_un serv_addr;
+#elif defined(_USE_UDS_SOCKET_TCP_)
+ struct sockaddr_un serv_addr;
#else
struct sockaddr_in serv_addr;
#endif
/*Create TCP Socket*/
#ifdef _USE_UDS_SOCKET_
ret = ms_ipc_create_client_socket(MS_PROTOCOL_TCP, MS_TIMEOUT_SEC_10, &sockfd, 0);
+#elif defined(_USE_UDS_SOCKET_TCP_)
+ ret = ms_ipc_create_client_tcp_socket(MS_PROTOCOL_TCP, MS_TIMEOUT_SEC_10, &sockfd, MS_DB_BATCH_UPDATE_TCP_PORT);
#else
ret = ms_ipc_create_client_socket(MS_PROTOCOL_TCP, MS_TIMEOUT_SEC_10, &sockfd);
#endif
serv_addr.sun_family = AF_UNIX;
MSAPI_DBG("%s", MEDIA_IPC_PATH[port]);
strcpy(serv_addr.sun_path, MEDIA_IPC_PATH[port]);
+#elif defined(_USE_UDS_SOCKET_TCP_)
+ serv_addr.sun_family = AF_UNIX;
+ MSAPI_DBG("%s", MEDIA_IPC_PATH[MS_DB_BATCH_UPDATE_TCP_PORT]);
+ strcpy(serv_addr.sun_path, MEDIA_IPC_PATH[MS_DB_BATCH_UPDATE_TCP_PORT]);
#else
serv_addr.sin_family = AF_INET;
- serv_addr.sin_addr.s_addr = inet_addr(SERVER_IP);
+ serv_addr.sin_addr.s_addr = htonl(INADDR_ANY);
+ //serv_addr.sin_addr.s_addr = inet_addr(SERVER_IP);
serv_addr.sin_port = htons(port);
#endif
#include <string.h>
#include <unistd.h>
#include <errno.h>
+#include <sys/types.h>
+#include <sys/stat.h>
#include "media-util-dbg.h"
#include "media-util.h"
{"/tmp/media_ipc_thumbcomm_client.dat"},
{"/tmp/media_ipc_thumbdaemon_client.dat"},
};
+#elif defined(_USE_UDS_SOCKET_TCP_)
+char MEDIA_IPC_PATH[][50] ={
+ {"/tmp/media_ipc_dbbatchupdate.dat"},
+ {"/tmp/media_ipc_thumbcreator.dat"},
+};
#endif
#ifdef _USE_UDS_SOCKET_
return MS_MEDIA_ERR_NONE;
}
+#ifdef _USE_UDS_SOCKET_TCP_
+int ms_ipc_create_client_tcp_socket(ms_protocol_e protocol, int timeout_sec, int *sock_fd, int port)
+{
+ int sock = -1;
+
+ struct timeval tv_timeout = { timeout_sec, 0 };
+
+ /*Create TCP Socket*/
+ if ((sock = socket(PF_FILE, SOCK_STREAM, 0)) < 0) {
+ MSAPI_DBG_ERR("socket failed: %s", strerror(errno));
+ return MS_MEDIA_ERR_SOCKET_CONN;
+ }
+
+ if (timeout_sec > 0) {
+ if (setsockopt(sock, SOL_SOCKET, SO_RCVTIMEO, &tv_timeout, sizeof(tv_timeout)) == -1) {
+ MSAPI_DBG_ERR("setsockopt failed: %s", strerror(errno));
+ close(sock);
+ return MS_MEDIA_ERR_SOCKET_CONN;
+ }
+ }
+
+ *sock_fd = sock;
+
+ return MS_MEDIA_ERR_NONE;
+}
+
+int ms_ipc_create_server_tcp_socket(ms_protocol_e protocol, int port, int *sock_fd)
+{
+ int i;
+ bool bind_success = false;
+ int sock = -1;
+
+ struct sockaddr_un serv_addr;
+ mode_t orig_mode;
+ orig_mode = umask(0);
+
+ /* Create a TCP socket */
+ if ((sock = socket(PF_FILE, SOCK_STREAM, 0)) < 0) {
+ MSAPI_DBG_ERR("socket failed: %s", strerror(errno));
+ return MS_MEDIA_ERR_SOCKET_CONN;
+ }
+
+ memset(&serv_addr, 0, sizeof(serv_addr));
+
+ serv_addr.sun_family = AF_UNIX;
+ MSAPI_DBG("%s", MEDIA_IPC_PATH[port]);
+ unlink(MEDIA_IPC_PATH[port]);
+ strcpy(serv_addr.sun_path, MEDIA_IPC_PATH[port]);
+
+ /* Bind to the local address */
+ for (i = 0; i < 20; i ++) {
+ if (bind(sock, (struct sockaddr *)&serv_addr, sizeof(serv_addr)) == 0) {
+ bind_success = true;
+ break;
+ }
+ MSAPI_DBG("%d",i);
+ usleep(250000);
+ }
+
+ if (bind_success == false) {
+ MSAPI_DBG_ERR("bind failed : %s %d_", strerror(errno), errno);
+ close(sock);
+ return MS_MEDIA_ERR_SOCKET_CONN;
+ }
+
+ MSAPI_DBG("bind success");
+
+ /* Listening */
+ if (listen(sock, SOMAXCONN) < 0) {
+ MSAPI_DBG_ERR("listen failed : %s", strerror(errno));
+ close(sock);
+ return MS_MEDIA_ERR_SOCKET_CONN;
+ }
+
+ MSAPI_DBG("Listening...");
+
+ *sock_fd = sock;
+
+ umask(orig_mode);
+ return MS_MEDIA_ERR_NONE;
+}
+
+#endif
+
int ms_ipc_create_server_socket(ms_protocol_e protocol, int port, int *sock_fd)
{
int i;
strcpy(serv_addr.sun_path, MEDIA_IPC_PATH[serv_port]);
#else
serv_addr.sin_family = AF_INET;
-// serv_addr.sin_addr.s_addr = htonl(INADDR_ANY);
- serv_addr.sin_addr.s_addr = inet_addr(SERVER_IP);
+ serv_addr.sin_addr.s_addr = htonl(INADDR_ANY);
+// serv_addr.sin_addr.s_addr = inet_addr(SERVER_IP);
serv_addr.sin_port = htons(serv_port);
#endif
/* Bind to the local address */
Name: media-server
Summary: File manager service server.
-Version: 0.2.44
+Version: 0.2.45
Release: 1
Group: utils
License: Apache License, Version 2.0
}
/* Create TCP Socket for batch query*/
+#ifdef _USE_UDS_SOCKET_TCP_
+ ret = ms_ipc_create_server_tcp_socket(MS_PROTOCOL_TCP, MS_DB_BATCH_UPDATE_TCP_PORT, &tcp_sockfd);
+#else
ret = ms_ipc_create_server_socket(MS_PROTOCOL_TCP, MS_DB_BATCH_UPDATE_PORT, &tcp_sockfd);
+#endif
if(ret != MS_MEDIA_ERR_NONE) {
/* Disconnect DB*/
media_db_disconnect(db_handle);
{
#ifdef _USE_UDS_SOCKET_
struct sockaddr_un client_addr;
+#elif defined(_USE_UDS_SOCKET_TCP_)
+ struct sockaddr_un client_addr;
#else
struct sockaddr_in client_addr;
#endif
#ifdef _USE_UDS_SOCKET_
if ((sock_fd = socket(AF_UNIX, SOCK_STREAM, 0)) < 0) {
+#elif defined(_USE_UDS_SOCKET_TCP_)
+ if ((sock_fd = socket(AF_UNIX, SOCK_STREAM, 0)) < 0) {
#else
if ((sock_fd = socket(PF_INET, SOCK_STREAM, IPPROTO_TCP)) < 0) {
#endif
{
#ifdef _USE_UDS_SOCKET_
struct sockaddr_un client_addr;
+#elif defined(_USE_UDS_SOCKET_TCP_)
+ struct sockaddr_un client_addr;
#else
struct sockaddr_in client_addr;
#endif
int sock;
unsigned short serv_port;
+#ifdef _USE_UDS_SOCKET_TCP_
+ serv_port = MS_THUMB_CREATOR_TCP_PORT;
+#else
serv_port = MS_THUMB_CREATOR_PORT;
+#endif
#if 0
#ifdef _USE_UDS_SOCKET_
MS_DBG("Listening...");
#endif
+
+#ifdef _USE_UDS_SOCKET_TCP_
+ if (ms_ipc_create_server_tcp_socket(MS_PROTOCOL_TCP, serv_port, &sock) < 0) {
+#else
if (ms_ipc_create_server_socket(MS_PROTOCOL_TCP, serv_port, &sock) < 0) {
+#endif
MS_DBG_ERR("_ms_thumb_create_socket failed");
return FALSE;
}