Index: trunk/test/socket.c
===================================================================
--- trunk/test/socket.c	(revision 122)
+++ trunk/test/socket.c	(revision 151)
@@ -8,12 +8,15 @@
 #include <string.h>
 
-#define LOG_SOCKET		0
-#define THREAD_POOL		1
+#define THREAD_POOL		2
 #define PORT			1234
-
-int socket_echo_server (void * arg)
+#define COUNT			2
+
+cf_ctx gLog;
+
+int server_worker (void * arg)
 {
-	int srvsock = *((int *)arg);
-	int clntsock = 0;
+	cf_ctx srvsock = (cf_ctx)arg;
+	cf_ctx clntsock = NULL;
+	int result = 0;
 	int recvd = 0;
 	char buf[1024] = {0x00,};
@@ -21,13 +24,13 @@
 
 	/*------------------------------------------------------------*/
-	clntsock = CF_Socket_Accept (srvsock);
-	if (clntsock < 0)
+	result = CF_Socket_Accept (srvsock, &clntsock);
+	if (result < 0)
 	{
 		CF_DEBUG_PRINT (stderr, "failed to accept on server\n");
 		return -1;
 	}
-	CF_Log_Write (LOG_SOCKET, "SERVER", "accepted\n");
-
-	for (i = 0 ; i < 5 ; i++)
+	CF_Log_Write (gLog, "SERVER", "accepted\n");
+
+	for (i = 0 ; i < COUNT ; i++)
 	{
 		if ((recvd = CF_Socket_Recv (clntsock, buf, sizeof (buf))) < 0)
@@ -36,6 +39,6 @@
 			return -2;
 		}
-		CF_Log_Write (LOG_SOCKET, "SERVER", "recv {%s}\n", buf);
-		CF_DEBUG_PRINT (stderr, "[SERVER] recv {%s}\n", buf);
+		CF_Log_Write (gLog, "SERVER", "recv {%s}\n", buf);
+		CF_DEBUG_PRINT (stderr, "recv {%s}\n", buf);
 
 		if (CF_Socket_Send (clntsock, buf, (size_t)recvd) < 0)
@@ -43,6 +46,6 @@
 			return -3;
 		}
-		CF_Log_Write (LOG_SOCKET, "SERVER", "resp {%s}\n", buf);
-		CF_DEBUG_PRINT (stderr, "[SERVER] resp {%s}\n", buf);
+		CF_Log_Write (gLog, "SERVER", "resp {%s}\n", buf);
+		CF_DEBUG_PRINT (stderr, "resp {%s}\n", buf);
 	}
 
@@ -53,7 +56,8 @@
 }
 
-int socket_echo_client (void * arg)
+int client_worker (void * arg)
 {
-	int sock = 0;
+	cf_ctx sock = NULL;
+	int result = 0;
 	int recvd = 0;
 	char buf[1024] = {0x00,};
@@ -63,21 +67,28 @@
 
 	/*------------------------------------------------------------*/
-	sock = CF_Socket_Connect ("localhost", PORT);
-	if (sock < 0)
+	result = CF_Socket_Create (&sock);
+	if (result < 0)
+	{
+		CF_DEBUG_PRINT (stderr, "failed to create\n");
+		return -1;
+	}
+
+	result = CF_Socket_Connect (sock, "localhost", PORT);
+	if (result < 0)
 	{
 		CF_DEBUG_PRINT (stderr, "failed to connect on client\n");
-		return -1;
-	}
-	CF_Log_Write (LOG_SOCKET, "CLIENT", "connected\n");
-
-	for (i = 0 ; i < 5 ; i++)
+		return -2;
+	}
+	CF_Log_Write (gLog, "CLIENT", "connected\n");
+
+	for (i = 0 ; i < COUNT ; i++)
 	{
 		if (CF_Socket_Send (sock, buf, sizeof (buf)) < 0)
 		{
 			CF_DEBUG_PRINT (stderr, "failed to send on client %d\n", errno);
-			return -2;
-		}
-		CF_Log_Write (LOG_SOCKET, "CLIENT", "sent {%s}\n", buf);
-		CF_DEBUG_PRINT (stderr, "[CLIENT] sent {%s}\n", buf);
+			return -3;
+		}
+		CF_Log_Write (gLog, "CLIENT", "sent {%s}\n", buf);
+		CF_DEBUG_PRINT (stderr, "sent {%s}\n", buf);
 
 		memset (buf, 0x00, sizeof (buf));
@@ -86,8 +97,8 @@
 		{
 			CF_DEBUG_PRINT (stderr, "failed to recv on client\n");
-			return -3;
-		}
-		CF_Log_Write (LOG_SOCKET, "CLIENT", "recv {%s}\n", buf);
-		CF_DEBUG_PRINT (stderr, "[CLIENT] recv {%s}\n", buf);
+			return -4;
+		}
+		CF_Log_Write (gLog, "CLIENT", "recv {%s}\n", buf);
+		CF_DEBUG_PRINT (stderr, "recv {%s}\n", buf);
 	}
 
@@ -100,30 +111,34 @@
 int main ()
 {
-	CF_Thread_Ctx stid[THREAD_POOL];
-	CF_Thread_Ctx ctid[THREAD_POOL];
-
-	int sock = 0;
+	cf_ctx stid[THREAD_POOL];
+	cf_ctx ctid[THREAD_POOL];
+
+	char ip[256] = {0x00,};
+	unsigned short port = 0;
+	cf_ctx sock = 0;
+	int result = 0;
 	int iter = 0;
 
 	/*------------------------------------------------------------*/
-	if (CF_Log_Initialize (1) < 0)
-	{
-		fprintf (stderr, "failed to init. log\n");
+	if (CF_Log_Create (&gLog, "socket.txt", CF_LOG_DEFAULT_BUFFER) < 0)
+		CF_DEBUG_PRINT (stderr, "failed to open log\n");
+
+	CF_Log_Write (gLog, "LOG_MULTITHREAD", "multi-threaded logging test with socket\n");
+
+	if (CF_Socket_Initialize () < 0)
+	{
+		CF_DEBUG_PRINT (stderr, "failed to initialize socket\n");
 		return -1;
 	}
-
-	if (CF_Log_Open (LOG_SOCKET, "socket.txt", CF_LOG_DEFAULT_BUFFER) < 0)
-		CF_DEBUG_PRINT (stderr, "failed to open log\n");
-
-	CF_Log_Write (LOG_SOCKET, "LOG_MULTITHREAD", "multi-threaded logging test with socket\n");
-
-	if (CF_Socket_Initialize () < 0)
-	{
-		CF_DEBUG_PRINT (stderr, "failed to initialize socket\n");
+	CF_Log_Write (gLog, "SOCKET", "socket initialized\n");
+
+	result = CF_Socket_Create (&sock);
+	if (result < 0)
+	{
+		CF_DEBUG_PRINT (stderr, "failed to create\n");
 		return -2;
 	}
-	CF_Log_Write (LOG_SOCKET, "SOCKET", "socket initialized\n");
-
-	sock = CF_Socket_Server (PORT, 5);
+
+	result = CF_Socket_Server (sock, PORT, 5);
 	if (sock < 0)
 	{
@@ -131,24 +146,28 @@
 		return -3;
 	}
-	CF_Log_Write (LOG_SOCKET, "SOCKET", "socket ready\n");
-
-	for (iter = 0 ; iter < THREAD_POOL ; iter++)
-	{
-		if (CF_Thread_CreateCtx (&stid[iter], socket_echo_server, &sock) < 0)
+	CF_Socket_GetIP (sock, ip);
+	CF_Socket_GetPort (sock, &port);
+	CF_Log_Write (gLog, "SOCKET", "socket ready [%s:%d]\n", ip, port);
+	CF_DEBUG_PRINT (stderr, "socket ready [%s:%d]\n", ip, port);
+ 
+
+	for (iter = 0 ; iter < THREAD_POOL ; iter++)
+	{
+		if (CF_Thread_Create (&stid[iter], server_worker, sock) < 0)
 		{
 			CF_DEBUG_PRINT (stderr, "failed to create %dth thread\n", iter);
 			return -4;
 		}
-		CF_Log_Write (LOG_SOCKET, "SOCKET", "create server thread-%d\n", iter);
-	}
-
-	for (iter = 0 ; iter < THREAD_POOL ; iter++)
-	{
-		if (CF_Thread_CreateCtx (&ctid[iter], socket_echo_client, &sock) < 0)
+		CF_Log_Write (gLog, "SOCKET", "create server thread-%d\n", iter);
+	}
+
+	for (iter = 0 ; iter < THREAD_POOL ; iter++)
+	{
+		if (CF_Thread_Create (&ctid[iter], client_worker, &sock) < 0)
 		{
 			CF_DEBUG_PRINT (stderr, "failed to create %dth thread\n", iter);
 			return -5;
 		}
-		CF_Log_Write (LOG_SOCKET, "SOCKET", "create client thread-%d\n", iter);
+		CF_Log_Write (gLog, "SOCKET", "create client thread-%d\n", iter);
 	}
 
@@ -174,10 +193,10 @@
 	{
 		CF_Thread_Join (ctid[iter]);
-		CF_Thread_DestroyCtx (ctid[iter]);
+		CF_Thread_Destroy (ctid[iter]);
 
 		CF_Thread_Join (stid[iter]);
-		CF_Thread_DestroyCtx (stid[iter]);
-
-		CF_Log_Write (LOG_SOCKET, "SOCKET", "join server thread-%d\n", iter);
+		CF_Thread_Destroy (stid[iter]);
+
+		CF_Log_Write (gLog, "SOCKET", "join server thread-%d\n", iter);
 	}
 
@@ -186,7 +205,5 @@
 	CF_Socket_Finalize ();
 
-	CF_Log_Close (LOG_SOCKET);
-
-	CF_Log_Finalize ();
+	CF_Log_Destroy (gLog);
 	/*------------------------------------------------------------*/
 
