Hi all... I have a server program that receives and sends UDP packets. Everytime there is UDP packet from a client, my server program will check the command and respond first with acknowledgement command and then followed by the real responds. Everytime server send a package, the packet will be put on packet checking queue which store its time of sending and no. of sending. So if more than 10 second I don't get any ack, I will send again the same package , set the time of sending and increment the no. of sending. After 3 times trying without any client respond then I will set user status as 'disconnected' or something like that. Here is the code snippet : void packetCheckThread(void *arg) { .... while(1) { pthread_mutex_lock(&sendList.mtx); while(sendList.noQueue == 0) pthread_cond_wait(&sendList.cond, &sendList.mtx); top = sendList.queue; info = top->info; pthread_mutex_unlock(&sendList.mtx); diff = 0; // Check the send time for (head) if (top != NULL && bValid) { diff = GetDiffTime(info.sendTime) ; if (diff > 10) { // if time out // Delete the item from list and return the list item ... if (cInfo.noSend < 3) { Trace("Resend packet again"); } } } } } note: - GetDiffTime() call time() to ask for the current time and find the difference with info.sendTime.. - packet queue structure: typedef struct { char ip[IPLEN]; // user's ip int port; // user's port char packetID[IPLEN]; // packet ID int dLen; // length of data char *pData; // Data int sendTime; // send time in unix format int noSend; // no of sending char etc[IPLEN]; // additional information, see packet.h } TSendInfo; Problems: 1. Why sometimes my program resending the packet less than 10 seconds interval, sometimes after only for 3 seconds. Does time() return the correct time? or is it thread safe? 2. I notice this thread checking function require a lot of CPu times since it is looping all the time if the checking queue is not empty. How to reduce this CPU time? 3. Currently I don't set any thread priorities but I want to make this packet checking thread run in the lowest priorities which
jamal
Posts
-
Linux Threads, UDP packet checking and timer -
Free drive space sites?Anybody knows URL sites for storing file internet for free? My friends want to send me file 9 MB using MSN or yahoo messenger but he can't transfer the file succesfully after tried it several times. I am thinking if he can store the file in some free space site and I can retrieve it later. jamal
-
KDE v's GNOMEI mostly use KDE for better integration between the apps and for programmming reason. KDE bases on Qt toolkit, a C++ library and it has a powerful free IDE called KDevelop. My favourite apps in KDE is Konqueror and KOffice. I install version 2.2 and it is very nice . jamal
-
1984I always thought facial recognition technology is still in very primitive form. I mean the advance in this technology for the last couple of years is not very great compare to other part of computer technology. Obviously it is not like in some holywood movie where any man face can be analyze and matched with stored data, but if this technology is already exist and mature, then I can imagine it will take so much budget to employee this technology across part of United state.
-
message to osama..I found this message to osama bin laden on eBay. Unfortunately he can't see this. There is no internet in Afghanistan. ;P :-D
-
streaming serverHi, i just wonder if there are examples or documentation on the net how to build a streaming server for movie or sound. I couldn't found any resources on the net.
-
What's going on with book pricesI guess probably it is because of australian GST :) But seriously, when I was in australia I bought some teechnical books and they cost almost the same as the original quoted price in USD. It was around 1995-1998. And also from my experience, It was better to buy books on campus bookstore, because there is discount even for non student and they have book sale. I once found "Programming Windows 95" by Petzold in an australian campus bookstore for $ASD 10.00, which is far a lot cheaper than the original price at $USD 49.95.
-
CodeProject is now running .NET beta 2Few days ago I find sometimes codeproject site was really slow. But, I notice that the page downloading is really fast now. Is it JUST because of these change? Wow...
-
QT toolkit for windowsHi... Probably you guys wanna try QT toolkit for win32. QT is C++ library for building multi platform application (see http://www.trolltech.com). It is based library for building KDE Linux Desktop environment (kde.org) But, this Qt for win32 is free downloadable for building Non-commercial windows applications. Here is the link: http://www.trolltech.com/products/download/freelicense/noncommercial-dl.html
-
Bugs in Ms WordI don't even know it is an easter egg. I am using Korean version of Microsoft window since I don't have the english version.
-
Bugs in Ms WordThere is a bug in Ms Word 2000 (probably you guys is already familiar with this bug ) which is very strange to me. Try this : 1) open a new word document 2) type "= rand (200,99)" (without " ") 3) press enter and wait for 3 seconds :confused:
-
Question about GetDlgItem()Thanks Chris for the link. It is very helpful. Codeproject is a great site and keep up the good work.
-
Question about GetDlgItem()Hi, I am reading jeff Prosise Book, "Programming Windows With MFC", I have a question regarding GetDlgItem() Function To obtain control pointer. In page 403, Jeff states that it is poor programming practice and dangerous at the same time to use statement like this: CListBox* pList= (CListBox*) GetDlgItem(IDC_LIST); I have seen many examples code that they are using this statement to obtain the pointer. Unfortunately, Jeff didn't explain why it is dangerous to use it. Anybody can explain to me why?