Changeset 38 in libcf
- Timestamp:
- 02/06/13 10:26:54 (11 years ago)
- Location:
- trunk
- Files:
-
- 4 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/include/cf_log.h
r35 r38 30 30 #define CF_LOG_BUFFER_DEFAULT -1 31 31 32 /** 로그 기록 시 버퍼를 사용하지 않고 즉시 기록 32 /** 33 * 로그 기록 시 버퍼를 사용하지 않고 즉시 기록 33 34 * 34 35 * @see CF_Log_CreateCtx, CF_LOG_OPEN, CF_Log_Initialize -
trunk/src/cf_log.c
r35 r38 84 84 // Initialize the present time to 0 and the timezone to UTC 85 85 unsigned __int64 ui64 =0; 86 static int tzflag = 0;86 //static int tzflag = 0; 87 87 88 88 if (NULL != tv) … … 105 105 } 106 106 107 /* 107 108 if (NULL != tz) 108 109 { … … 117 118 tz->tz_dsttime = _daylight; 118 119 } 120 */ 119 121 120 122 return 0; … … 166 168 return CF_ERROR_LOG_FLUSH; 167 169 168 memset (ctx->buffer, 0x00, ctx->size);169 170 ctx->length = 0; 170 171 … … 209 210 else /* flush되어야 함. */ 210 211 { 211 if (CF_File_Write (ctx->fd, buffer, demandSize) < 0) 212 ctx->buffer = (char *)buffer; 213 ctx->length = demandSize; 214 215 if (CF_Log_Local_Flush (ctx) < 0) 212 216 return CF_ERROR_LOG_FLUSH; 213 217 } … … 338 342 return CF_ERROR_LOG_INVALID_CTX; 339 343 340 memset (context->path, 0x00, sizeof (context->path)); 341 342 if (context->buffer != NULL) 344 if (context->size > 0) 343 345 { 344 346 CF_Log_Flush (ctx); -
trunk/test/makefile
r35 r38 81 81 make dep 82 82 $(LD) $(LDFLAGS) $(LIBS) $(CDEFS) $(CFLAGS) $(INCLUDES) -o $(TARGET_PATH)/$@.$(EXT_EXECUTE) $? 83 LD_LIBRARY_PATH=$(TARGET_PATH) $(TARGET_PATH)/$@.$(EXT_EXECUTE)83 cd $(TARGET_PATH); LD_LIBRARY_PATH=. ./$@.$(EXT_EXECUTE) 84 84 85 85 clean: dummy -
trunk/test/test.c
r35 r38 29 29 const char * file = "./log.txt"; 30 30 31 CF_THREAD_RETURN CF_THREAD_CALL test_log_mt (void * arg) 32 { 33 int i = 0; 34 int th = *((int *)arg); 35 36 for (i = 0 ; i < 100000 ; i++) 37 { 38 CF_Log_Write (gLogCtx, "LOG_MT", "[%d] multi-threadedlogging test %d\n", th, i); 39 } 40 41 return (CF_THREAD_RETURN)0; 42 } 43 31 44 void test_log (const char * message) 32 45 { 33 46 int i, j; 34 47 char idname[16] = {0x00,}; 48 CF_Thread tid[10]; 35 49 36 50 CF_DEBUG_CALLSTACK_PUSH (gDebugCtx); … … 44 58 CF_DEBUG_PRINT (stderr, "create log ctx error\n"); 45 59 46 for (i = 0 ; i < 1000 0; i++)60 for (i = 0 ; i < 1000 ; i++) 47 61 CF_Log_Write (gLogCtx, "LOG_TEST", "turn %d\n", i); 48 62 … … 74 88 /* }}} id */ 75 89 90 /* mt {{{ */ 91 gLogCtx = CF_Log_CreateCtx ("log_mt.txt", CF_LOG_BUFFER_DEFAULT); 92 if (gLogCtx == NULL) 93 CF_DEBUG_PRINT (stderr, "create log ctx error\n"); 94 95 if (CF_Log_SetMultiThread (gLogCtx) < 0) 96 CF_DEBUG_PRINT (stderr, "set multi-threading mode error\n"); 97 98 for (i = 0 ; i < 10 ; i++) 99 { 100 if (CF_Thread_Create (&tid[i], test_log_mt, &i) < 0) 101 { 102 CF_DEBUG_PRINT (stderr, "failed to create %dth thread\n", i); 103 return ; 104 } 105 CF_DEBUG_PRINT (stderr, "created %dth thread\n", i); 106 } 107 108 for (i = 0 ; i < 10 ; i++) 109 { 110 if (CF_Thread_Join (&tid[i]) < 0) 111 CF_DEBUG_PRINT (stderr, "failed to join %dth thread\n", i); 112 } 113 114 CF_Log_DestroyCtx (gLogCtx); 115 /* }}} mt */ 116 76 117 /* finalize */ 77 118 CF_Log_Finalize (); … … 89 130 CF_DEBUG_TRACE (gDebugCtx, "what the ... file open ?\n"); 90 131 91 if (CF_File_Read (fd, buffer, sizeof (buffer) - 1) < 0)132 if (CF_File_Read (fd, buffer, sizeof (buffer)) < 0) 92 133 CF_DEBUG_TRACE (gDebugCtx, "what the ... file read ?\n"); 93 134 else 94 135 CF_DEBUG_TRACE_BIN (gDebugCtx, (unsigned char *)buffer, 95 sizeof (buffer) - 1,136 sizeof (buffer), 96 137 "-- %d bytes of %d bytes\n", 97 sizeof (buffer) - 1,138 sizeof (buffer), 98 139 CF_File_GetSize (fd)); 99 140 … … 134 175 int recvd = 0; 135 176 char buf[1024] = {0x00,}; 177 int i = 0; 136 178 137 179 /*------------------------------------------------------------*/ … … 142 184 return (CF_THREAD_RETURN)-1; 143 185 } 144 CF_DEBUG_PRINT (stderr, "SERVER : accepted\n");145 186 CF_Log_Write (gLogCtx, "SERVER", "accepted\n"); 146 187 147 if ((recvd = CF_Socket_Recv (clntsock, buf, sizeof (buf))) < 0) 148 { 149 CF_DEBUG_PRINT (stderr, "failed to recv on server\n"); 150 return (CF_THREAD_RETURN)-2; 151 } 152 CF_DEBUG_PRINT (stderr, "SERVER : recv {%s}\n", buf); 153 CF_Log_Write (gLogCtx, "SERVER", "recv {%s}\n", buf); 154 155 if (CF_Socket_Send (clntsock, buf, recvd) < 0) 156 { 157 CF_DEBUG_PRINT (stderr, "failed to send on server\n"); 158 return (CF_THREAD_RETURN)-3; 159 } 160 CF_DEBUG_PRINT (stderr, "SERVER : resp {%s}\n", buf); 161 CF_Log_Write (gLogCtx, "SERVER", "resp {%s}\n", buf); 188 for (i = 0 ; i < 100 ; i++) 189 { 190 if ((recvd = CF_Socket_Recv (clntsock, buf, sizeof (buf))) < 0) 191 { 192 CF_DEBUG_PRINT (stderr, "failed to recv on server\n"); 193 return (CF_THREAD_RETURN)-2; 194 } 195 CF_Log_Write (gLogCtx, "SERVER", "recv {%s}\n", buf); 196 197 if (CF_Socket_Send (clntsock, buf, recvd) < 0) 198 { 199 return (CF_THREAD_RETURN)-3; 200 } 201 CF_Log_Write (gLogCtx, "SERVER", "resp {%s}\n", buf); 202 } 203 204 CF_Socket_Close (clntsock); 162 205 163 206 return (CF_THREAD_RETURN)0; … … 170 213 int recvd = 0; 171 214 char buf[1024] = {0x00,}; 215 int i = 0; 172 216 173 217 sprintf (buf, "...wow ? is it succeed ?"); … … 180 224 return (CF_THREAD_RETURN)-1; 181 225 } 182 CF_DEBUG_PRINT (stderr, "CLIENT : connected\n");183 226 CF_Log_Write (gLogCtx, "CLIENT", "connected\n"); 184 227 185 if (CF_Socket_Send (sock, buf, sizeof (buf)) < 0) 186 { 187 CF_DEBUG_PRINT (stderr, "failed to send on client %d\n", errno); 188 return (CF_THREAD_RETURN)-2; 189 } 190 CF_DEBUG_PRINT (stderr, "CLIENT : sent {%s}\n", buf); 191 CF_Log_Write (gLogCtx, "CLIENT", "sent {%s}\n", buf); 192 193 memset (buf, 0x00, sizeof (buf)); 194 195 if ((recvd = CF_Socket_Recv (sock, buf, sizeof (buf))) < 0) 196 { 197 CF_DEBUG_PRINT (stderr, "failed to recv on client\n"); 198 return (CF_THREAD_RETURN)-3; 199 } 200 CF_DEBUG_PRINT (stderr, "CLIENT : recv {%s}\n", buf); 201 CF_Log_Write (gLogCtx, "CLIENT", "recv {%s}\n", buf); 228 for (i = 0 ; i < 100 ; i++) 229 { 230 if (CF_Socket_Send (sock, buf, sizeof (buf)) < 0) 231 { 232 CF_DEBUG_PRINT (stderr, "failed to send on client %d\n", errno); 233 return (CF_THREAD_RETURN)-2; 234 } 235 CF_Log_Write (gLogCtx, "CLIENT", "sent {%s}\n", buf); 236 237 memset (buf, 0x00, sizeof (buf)); 238 239 if ((recvd = CF_Socket_Recv (sock, buf, sizeof (buf))) < 0) 240 { 241 CF_DEBUG_PRINT (stderr, "failed to recv on client\n"); 242 return (CF_THREAD_RETURN)-3; 243 } 244 CF_Log_Write (gLogCtx, "CLIENT", "recv {%s}\n", buf); 245 } 202 246 203 247 CF_Socket_Close (sock); … … 267 311 for (iter = 0 ; iter < THREAD_POOL ; iter++) 268 312 { 269 CF_DEBUG_PRINT (stderr, "tid[%d] 0x%08x\n", iter, tid[iter]);270 313 CF_Thread_Join (&tid[iter]); 271 314 CF_Thread_Release (&tid[iter]); … … 300 343 301 344 // 4 302 CF_DEBUG_PRINT (stderr, " == MULTI-THREADED SOCKET TEST with MULTI-THREADED LOGGING==\n");345 CF_DEBUG_PRINT (stderr, " == MULTI-THREADED SOCKET TEST ==\n"); 303 346 test_socket (); 304 347
Note:
See TracChangeset
for help on using the changeset viewer.