comm.h 761 Bytes
Newer Older
1 2 3 4 5 6 7 8 9
#ifndef _COMM_H
#define	_COMM_H

#include <sys/types.h>
#include <sys/socket.h>

#include "jvmtihelper.h"

// sends data over network
10
void send_data(int sockfd, const void * data, int data_len) {
11 12 13 14 15 16 17 18 19 20 21 22 23

	int sent = 0;

	while (sent != data_len) {

		int res = send(sockfd, ((unsigned char *)data) + sent,
				(data_len - sent), 0);
		check_std_error(res, -1, "Error while sending data to server");
		sent += res;
	}
}

// receives data from network
24
void rcv_data(int sockfd, void * data, int data_len) {
25 26 27 28 29 30 31 32 33 34 35 36 37 38

	int received = 0;

	while (received != data_len) {

		int res = recv(sockfd, ((unsigned char *)data) + received,
				(data_len - received), 0);
		check_std_error(res, -1, "Error while receiving data from server");

		received += res;
	}
}

#endif	/* _COMM_H */