-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathlasync.cpp
More file actions
92 lines (81 loc) · 2.18 KB
/
Copy pathlasync.cpp
File metadata and controls
92 lines (81 loc) · 2.18 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
/*************************************************************************
> File Name: main.cpp
> Created Time: Mon 21 Aug 2017 03:14:57 PDT
************************************************************************/
#include <string>
#include <fstream>
#include <iostream>
using namespace std;
#include <stdio.h>
#include <string.h>
#include <stdlib.h>
#include <unistd.h>
#include <sys/socket.h>
#include <netinet/in.h>
#include <stdlib.h>
#include <sys/types.h>
#include <arpa/inet.h>
#include "netutils.h"
#include "configparse.h"
#include "nfsutils.h"
#include "strutils.h"
int main(int argc,char *argv[])
{
//含有goto语句的不能在goto语句中定义变量
int sendtoret;
int bufflen;
int sockfd ;
char * msg;
Message *pmsg;
string sharedir;
int ret;
char * ch = pmsg->tag;
gpparse->initkvmap("conf/lasync.conf");
msg = netutils::buildmsg(argc, argv, bufflen);
if(!msg)
{
cerr << "can not build message" << endl;
goto ERROR;
}
//export share dir via nfs
ret = gpparse->getvalue("sharedir", sharedir);
if(!nfsutils::isexported(sharedir))
{
ret = nfsutils::confignfs(sharedir);
ret += nfsutils::nfsstart();
if(!ret)
{
cerr << "cannot config nfs" << sharedir << endl;
exit(1);
}
}
pmsg = (Message *)msg;
cout << "==============Message============" << endl;
cout << "buffer cmd :" << pmsg->cmd << endl;
cout << "buffer sharedir :" << pmsg->sharedirlen << endl;
cout << "buffer machines:" << (pmsg->tag)+pmsg->sharedirlen << endl;
//init socket fd send data
sockfd = netutils::initsocket();
//init dest for sockfd
struct sockaddr_in dest;
netutils::initdest(dest);
//sendto() 向服务器发送数据
sendtoret = sendto(sockfd, msg, bufflen+1, 0,
(struct sockaddr*)&dest, sizeof(sockaddr_in));
if (sendtoret < 0) //失败返回负数
{
perror("sendto");
goto ERROR;
}
//close fd and exit
close(sockfd);
free(msg);
msg = NULL;
exit(EXIT_SUCCESS);
ERROR:
close(sockfd);
free(msg);
msg = NULL;
exit(1);
return 0;
}