c++ - Array of sockets as a parameters in CreateThread -
i have exmaple wich describes how send 1 socket parameter new thread.
socket clientsocket; ... createthread(null, null, sextoclient, &clientsocket, null, &thid); ...} dword winapi sextoclient(lpvoid client) { socket clientsocket; clientsocket = ((socket*)client)[0]; ... }
but want make thread array of sockets. how can send them , use in thread?
and mean [0] @ end of line? in particular example we're send 1 socket , it's working fine.
((socket*)client)[0];
you can pass arguments createthread method wrapping arguments simple structure. example:
struct threadparams { std::vector<socket *> sockets; std::string clientname; // more params };
all need initialize structure before calling createthread function, , pass pointer:
threadparams * params = new threadparams(); params.setparameters(); createthread(, , sextoclient, params, ); dword winapi sextoclient(lpvoid arg) { threadparams * params = reinterpret_cast<threadparams *>(arg); // delete after usage; delete params; }
Comments
Post a Comment