Example #1
0
/**
 * @brief Wrapper to read and test from a socket
 * @param sock The socket to read from
 * @param data The data to send before test
 * @param test The string to test for
 * @return 0 if successful, -1 if failure
 */
int proto_write_test(int sock, char *data, char *test)
{

	if (socket_send_all(sock, data, strlen(data)) == 0) {
		return proto_read_test(sock, test);
	}
	return -1;
}
Example #2
0
/**
 * @brief Wrapper to send a generic query
 * @param s The server settings
 * @param user The data to query with
 * @return The resulting information, or NULL
 */
char *proto_gen_write(struct server_data *s, char *data)
{
	int r;
	char *buffer = NULL;
	int sock;

	sock = open_tcp_client(s->server, s->port);
	if (socket_send_all(sock, data, strlen(data)) == 0) {
		buffer = socket_recv_all(sock, &r);
	}
	socket_close(sock);
	free(data);

	return buffer;
}
Example #3
0
int Socket::send_all(const void* buffer, size_t size, size_t& bytes_send) const {
	return socket_send_all(sock, buffer, size, &bytes_send);
}