Conversation
|
Não descobri como impedir o commit do readme feito pelo gihub. |
Math-42
left a comment
There was a problem hiding this comment.
No geral, remova todas as políticas de dentro do socket, deixe ele apenas como uma ferramenta de enviar e ler bytes e outras funcionalidades como bind, listen e etc, no geral pecou apenas pelo excesso.
|
|
||
| Message(std::string send, std::string sent, std::string mess) | ||
| : send_to { std::move(send) } |
There was a problem hiding this comment.
Trocar abreviação de message para message ou pra msg
| #define SOCKET_NAME "/tmp/server.socket" | ||
| #define STD_SIZE 128 |
There was a problem hiding this comment.
remover esses defines trocar para atributos internos, trocar por atributos internos da classe.
| static int start(); | ||
|
|
||
| static int openSocket(std::string name); | ||
|
|
||
| static int listenClient(SocketHandler::Message* com, struct timeval dropout_time); | ||
|
|
||
| static int listenServer(int* sockets, std::string* connection_list, int size, SocketHandler::Message* server_com, struct timeval dropout_time); | ||
|
|
||
| static int sendMessage(int socket, Message com); | ||
|
|
||
| static void closeSocket(int dis_socket); |
There was a problem hiding this comment.
Não precisa ser static, se não não será possível criar mais de um socket.
|
|
||
| static int transfer(Message com, int* sockets, int size); | ||
|
|
||
| static Message strToMsg(char* com); |
| /** Converts strings to Message format | ||
| * @param com string to be converted | ||
| * @return returns Message recovered from string | ||
| */ | ||
| SocketHandler::Message SocketHandler::strToMsg(char* com) { | ||
| std::string cut[3]; | ||
| int i = 0, j = 0; | ||
| while (com[i] != '\0' && j < 3) { | ||
| if (com[i] != ',') { | ||
| cut[j] += com[i]; | ||
| } | ||
| else { | ||
| j++; | ||
| } | ||
| i++; | ||
| } | ||
|
|
||
| SocketHandler::Message mes {cut[0], cut[1], cut[2]}; | ||
|
|
||
| return mes; | ||
| } |
There was a problem hiding this comment.
A ideia do socket é que ele seja agnóstico e envie apena bytes, não precisa se preocupar nesse nível de implementação sobre converter strings, lidar com tipos de dados e etc. Nesse caso essa função não é necessária.
|
|
||
| if (atoi(buffer) == -1) { | ||
| printf("message not sent\n"); | ||
| } | ||
| else if (atoi(buffer) == 0) { | ||
| printf("destination unavailable\n"); | ||
| } | ||
|
|
There was a problem hiding this comment.
Apenas disparar o erro (throw), não precisa se preocupar imprimir o erro.
| int SocketHandler::sendMessage(int socket, SocketHandler::Message com) { | ||
| std::string men = com.send_to + "," + com.sent_from + "," + com.message; | ||
|
|
There was a problem hiding this comment.
Como já dito, se preocupe em apenas enviar uma quantidade de n bytes, não precisa construir a mensagem ainda.
Added socket handler class, with functions for the communication between server and clients through unix sockets.