aboutsummaryrefslogblamecommitdiffstatshomepage
path: root/src/client.c
blob: 972ebbd490bbfcdb43a0c914c28a61e52602ceb6 (plain) (tree)
1
2
3
4
5
6
7
8
9
                   
                





                                                                         
                                                                 













                                                                    
                                      
 
                                                                      




                           
#include "client.h"
#include "msg.h"
#include "net.h"

#include <unistd.h>

int client_create(struct client *client, const struct settings *settings)
{
	client->fd = net_connect(settings->host, settings->port);
	if (client->fd < 0)
		return client->fd;

	return 0;
}

void client_destroy(const struct client *client)
{
	close(client->fd);
}

int client_main(const struct client *client, int argc, char *argv[])
{
	int result, ret = 0;
	struct msg msg = {argc, argv};

	ret = msg_send_and_wait_for_result(client->fd, &msg, &result);
	if (ret < 0)
		return ret;

	return result;
}