Server.h 867 B

12345678910111213141516171819202122232425262728293031323334353637383940414243
  1. #ifndef SERVER_H
  2. #define SERVER_H
  3. #include <pthread.h>
  4. #include "Stream.h"
  5. typedef struct Server
  6. {
  7. int maxClients;
  8. short port;
  9. pthread_t* threads;
  10. int* clientSockets;
  11. char** clientUser;
  12. int connectSocket;
  13. int hAmount;
  14. int hIndex;
  15. ServerStreamFunction* handlers;
  16. char* directory;
  17. } Server;
  18. typedef struct ThreadData
  19. {
  20. int id;
  21. Server* server;
  22. } ThreadData;
  23. void serverInitDefaults(Server* s);
  24. int serverInit(Server* s, int maxClients, short port, char* directory);
  25. void serverRemove(Server* s);
  26. int serverSend(int clientSocket, Stream* out);
  27. void serverWaitForConnection(Server* s);
  28. void serverRegisterHandler(Server* s, ServerStreamFunction f);
  29. int serverSetUser(Server* s, int clientId, char* name);
  30. char* serverGetUser(Server* s, int clientId);
  31. void serverFreeUser(Server* s, int clientId);
  32. #endif