Click here to Skip to main content
15,921,660 members
Home / Discussions / C / C++ / MFC
   

C / C++ / MFC

 
GeneralRe: Mutex WaitForSingleObject does not Signal Pin
ForNow11-Dec-16 0:17
ForNow11-Dec-16 0:17 
GeneralRe: Mutex WaitForSingleObject does not Signal Pin
Munchies_Matt11-Dec-16 21:48
Munchies_Matt11-Dec-16 21:48 
QuestionC++ Pin
Member 1287185126-Nov-16 3:50
Member 1287185126-Nov-16 3:50 
AnswerRe: C++ Pin
PIEBALDconsult26-Nov-16 4:10
mvePIEBALDconsult26-Nov-16 4:10 
AnswerRe: C++ Pin
Richard MacCutchan26-Nov-16 4:12
mveRichard MacCutchan26-Nov-16 4:12 
AnswerRe: C++ Pin
Afzaal Ahmad Zeeshan26-Nov-16 4:39
professionalAfzaal Ahmad Zeeshan26-Nov-16 4:39 
AnswerRe: C++ Pin
Patrice T29-Nov-16 17:14
mvePatrice T29-Nov-16 17:14 
QuestionGame dev tutorials for c++ Pin
dolfijn300025-Nov-16 7:48
dolfijn300025-Nov-16 7:48 
AnswerRe: Game dev tutorials for c++ Pin
Afzaal Ahmad Zeeshan26-Nov-16 4:44
professionalAfzaal Ahmad Zeeshan26-Nov-16 4:44 
GeneralRe: Game dev tutorials for c++ Pin
dolfijn300026-Nov-16 6:59
dolfijn300026-Nov-16 6:59 
GeneralRe: Game dev tutorials for c++ Pin
Afzaal Ahmad Zeeshan26-Nov-16 8:45
professionalAfzaal Ahmad Zeeshan26-Nov-16 8:45 
AnswerRe: Game dev tutorials for c++ Pin
CPallini28-Nov-16 21:56
mveCPallini28-Nov-16 21:56 
QuestionUsing multiple cores within a single thread in C++ and MFC Pin
TQTL22-Nov-16 6:43
professionalTQTL22-Nov-16 6:43 
AnswerRe: Using multiple cores within a single thread in C++ and MFC Pin
Richard MacCutchan22-Nov-16 8:38
mveRichard MacCutchan22-Nov-16 8:38 
AnswerRe: Using multiple cores within a single thread in C++ and MFC Pin
Patrice T22-Nov-16 10:54
mvePatrice T22-Nov-16 10:54 
AnswerRe: Using multiple cores within a single thread in C++ and MFC Pin
Randor 22-Nov-16 12:27
professional Randor 22-Nov-16 12:27 
AnswerRe: Using multiple cores within a single thread in C++ and MFC Pin
David Crow22-Nov-16 12:48
David Crow22-Nov-16 12:48 
AnswerRe: Using multiple cores within a single thread in C++ and MFC Pin
leon de boer22-Nov-16 19:15
leon de boer22-Nov-16 19:15 
QuestionRun time validation in .RC file in VC++ Mfc application Pin
rajmohanpatel21-Nov-16 23:50
rajmohanpatel21-Nov-16 23:50 
AnswerRe: Run time validation in .RC file in VC++ Mfc application Pin
Jochen Arndt22-Nov-16 0:11
professionalJochen Arndt22-Nov-16 0:11 
QuestionTCP server handle Clients, std::map or array? Pin
bestbear20-Nov-16 5:03
bestbear20-Nov-16 5:03 
AnswerRe: TCP server handle Clients, std::map or array? Pin
Afzaal Ahmad Zeeshan20-Nov-16 21:36
professionalAfzaal Ahmad Zeeshan20-Nov-16 21:36 
GeneralRe: TCP server handle Clients, std::map or array? Pin
bestbear20-Nov-16 22:23
bestbear20-Nov-16 22:23 
AnswerRe: TCP server handle Clients, std::map or array? Pin
Jochen Arndt21-Nov-16 0:22
professionalJochen Arndt21-Nov-16 0:22 
Some thoughts about your posts (the initial one and the above reply to Afzaal Ahmad Zeeshan).

Do you really need to store the IP? If so, don't store it as string.

There is no need to generate a (re-usable) connect ID. You already have one:
The connection socket handle.
Using the handle avoids also storing the IP because you can get the IP from the handle using getpeername. But using the handle makes using a map more appropriate.

There is also a solution to avoid locking at all:
Just let the functions be executed in the same thread. As far as I understand there are three events: connection, disconnection, and periodical updates. If connection and disconnection are events issued from other threads, implement signaling functions passing the socket handle.

My suggestion:
Use a map storing the socket handle and avoid locking by putting all associated functions into a single thread.
GeneralRe: TCP server handle Clients, std::map or array? Pin
bestbear21-Nov-16 1:11
bestbear21-Nov-16 1:11 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.