use newest files from libfastcommon

pull/48/head
yuqing 2014-08-10 14:01:58 +08:00
parent be6e9f1141
commit 95800612dc
8 changed files with 21 additions and 15 deletions

View File

@ -5,7 +5,7 @@ Version 5.03 2014-08-10
* use newest logger from libfastcommon * use newest logger from libfastcommon
* patches by liangry@ucweb.com * patches by liangry@ucweb.com
* bug fixed: can't sync large files cause by v5.02 * bug fixed: can't sync large files cause by v5.02
* use newest ioevent_loop from libfastcommon * use newest files from libfastcommon
Version 5.02 2014-07-20 Version 5.02 2014-07-20
* corect README spell mistake * corect README spell mistake

View File

@ -3,6 +3,7 @@
#include <errno.h> #include <errno.h>
#include <sys/resource.h> #include <sys/resource.h>
#include <pthread.h> #include <pthread.h>
#include <assert.h>
#include "fast_mblock.h" #include "fast_mblock.h"
#include "logger.h" #include "logger.h"
#include "shared_func.h" #include "shared_func.h"
@ -21,7 +22,7 @@ int fast_mblock_init(struct fast_mblock_man *mblock, const int element_size, \
return EINVAL; return EINVAL;
} }
mblock->element_size = element_size; mblock->element_size = MEM_ALIGN(element_size);
if (alloc_elements_once > 0) if (alloc_elements_once > 0)
{ {
mblock->alloc_elements_once = alloc_elements_once; mblock->alloc_elements_once = alloc_elements_once;
@ -30,7 +31,7 @@ int fast_mblock_init(struct fast_mblock_man *mblock, const int element_size, \
{ {
int block_size; int block_size;
block_size = MEM_ALIGN(sizeof(struct fast_mblock_node) \ block_size = MEM_ALIGN(sizeof(struct fast_mblock_node) \
+ element_size); + mblock->element_size);
mblock->alloc_elements_once = (1024 * 1024) / block_size; mblock->alloc_elements_once = (1024 * 1024) / block_size;
} }
@ -44,6 +45,7 @@ int fast_mblock_init(struct fast_mblock_man *mblock, const int element_size, \
mblock->malloc_chain_head = NULL; mblock->malloc_chain_head = NULL;
mblock->free_chain_head = NULL; mblock->free_chain_head = NULL;
mblock->total_count = 0;
return 0; return 0;
} }
@ -84,12 +86,12 @@ static int fast_mblock_prealloc(struct fast_mblock_man *mblock)
pNode = (struct fast_mblock_node *)p; pNode = (struct fast_mblock_node *)p;
pNode->next = (struct fast_mblock_node *)(p + block_size); pNode->next = (struct fast_mblock_node *)(p + block_size);
} }
((struct fast_mblock_node *)pLast)->next = NULL; ((struct fast_mblock_node *)pLast)->next = NULL;
mblock->free_chain_head = (struct fast_mblock_node *)pTrunkStart; mblock->free_chain_head = (struct fast_mblock_node *)pTrunkStart;
pMallocNode->next = mblock->malloc_chain_head; pMallocNode->next = mblock->malloc_chain_head;
mblock->malloc_chain_head = pMallocNode; mblock->malloc_chain_head = pMallocNode;
mblock->total_count += mblock->alloc_elements_once;
return 0; return 0;
} }
@ -114,6 +116,7 @@ void fast_mblock_destroy(struct fast_mblock_man *mblock)
} }
mblock->malloc_chain_head = NULL; mblock->malloc_chain_head = NULL;
mblock->free_chain_head = NULL; mblock->free_chain_head = NULL;
mblock->total_count = 0;
pthread_mutex_destroy(&(mblock->lock)); pthread_mutex_destroy(&(mblock->lock));
} }
@ -189,7 +192,7 @@ int fast_mblock_free(struct fast_mblock_man *mblock, \
return 0; return 0;
} }
int fast_mblock_count(struct fast_mblock_man *mblock) int fast_mblock_free_count(struct fast_mblock_man *mblock)
{ {
struct fast_mblock_node *pNode; struct fast_mblock_node *pNode;
int count; int count;

View File

@ -37,11 +37,12 @@ struct fast_mblock_man
struct fast_mblock_malloc *malloc_chain_head; //malloc chain to be freed struct fast_mblock_malloc *malloc_chain_head; //malloc chain to be freed
int element_size; //element size int element_size; //element size
int alloc_elements_once; //alloc elements once int alloc_elements_once; //alloc elements once
int total_count; //total element count
pthread_mutex_t lock; //the lock for read / write free node chain pthread_mutex_t lock; //the lock for read / write free node chain
}; };
#define fast_mblock_to_node_ptr(data_ptr) \ #define fast_mblock_to_node_ptr(data_ptr) \
(struct fast_mblock_node *)(data_ptr - ((size_t)(char *) \ (struct fast_mblock_node *)((char *)data_ptr - ((size_t)(char *) \
&((struct fast_mblock_node *)0)->data)) &((struct fast_mblock_node *)0)->data))
#ifdef __cplusplus #ifdef __cplusplus
@ -90,7 +91,9 @@ parameters:
mblock: the mblock pointer mblock: the mblock pointer
return the free node count of the mblock, return -1 if fail return the free node count of the mblock, return -1 if fail
*/ */
int fast_mblock_count(struct fast_mblock_man *mblock); int fast_mblock_free_count(struct fast_mblock_man *mblock);
#define fast_mblock_total_count(mblock) (mblock)->total_count
#ifdef __cplusplus #ifdef __cplusplus
} }

View File

@ -47,7 +47,7 @@ struct nio_thread_data
struct fast_task_info struct fast_task_info
{ {
IOEventEntry event; IOEventEntry event; //must first
char client_ip[IP_ADDRESS_SIZE]; char client_ip[IP_ADDRESS_SIZE];
void *arg; //extra argument pointer void *arg; //extra argument pointer
char *data; //buffer for write or recv char *data; //buffer for write or recv

View File

@ -10,6 +10,7 @@
#include <stdio.h> #include <stdio.h>
#include <string.h> #include <string.h>
#include <errno.h> #include <errno.h>
#include <inttypes.h>
#include "pthread_func.h" #include "pthread_func.h"
#include "hash.h" #include "hash.h"

View File

@ -19,20 +19,20 @@ static void deal_ioevents(IOEventPoller *ioevent, const int count)
static void deal_timeouts(FastTimerEntry *head) static void deal_timeouts(FastTimerEntry *head)
{ {
FastTimerEntry *entry; FastTimerEntry *entry;
FastTimerEntry *curent; FastTimerEntry *current;
IOEventEntry *pEventEntry; IOEventEntry *pEventEntry;
entry = head->next; entry = head->next;
while (entry != NULL) while (entry != NULL)
{ {
curent = entry; current = entry;
entry = entry->next; entry = entry->next;
pEventEntry = (IOEventEntry *)curent->data; pEventEntry = (IOEventEntry *)current->data;
if (pEventEntry != NULL) if (pEventEntry != NULL)
{ {
pEventEntry->callback(pEventEntry->fd, IOEVENT_TIMEOUT, pEventEntry->callback(pEventEntry->fd, IOEVENT_TIMEOUT,
curent->data); current->data);
} }
} }
} }

View File

@ -13,6 +13,7 @@
#include <ctype.h> #include <ctype.h>
#include <unistd.h> #include <unistd.h>
#include <signal.h> #include <signal.h>
#include <inttypes.h>
#include <sys/types.h> #include <sys/types.h>
#include <sys/stat.h> #include <sys/stat.h>
#include <netinet/in.h> #include <netinet/in.h>
@ -1770,8 +1771,7 @@ int parse_bytes(char *pStr, const int default_unit_bytes, int64_t *bytes)
if (*bytes < 0) if (*bytes < 0)
{ {
logError("file: "__FILE__", line: %d, " \ logError("file: "__FILE__", line: %d, " \
"bytes: %"PRId64" < 0", \ "bytes: %"PRId64" < 0", __LINE__, *bytes);
__LINE__, *bytes);
return EINVAL; return EINVAL;
} }

View File

@ -239,7 +239,6 @@ int tcpsenddata(int sock, void* data, const int size, const int timeout)
if (pollfds.revents & POLLHUP) if (pollfds.revents & POLLHUP)
{ {
return ENOTCONN; return ENOTCONN;
break;
} }
#endif #endif