MCPcopy Create free account
hub / github.com/axmolengine/axmol / uploadFile

Method uploadFile

tests/cpp-tests/Source/ConsoleTest/ConsoleTest.cpp:124–253  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

122ConsoleUploadFile::~ConsoleUploadFile() {}
123
124void ConsoleUploadFile::uploadFile()
125{
126 Data srcFileData = FileUtils::getInstance()->getDataFromFile(s_pathGrossini);
127 if (srcFileData.isNull())
128 {
129 AXLOGE("ConsoleUploadFile: could not open file {}", s_pathGrossini);
130 }
131
132 std::string targetFileName = _targetFileName;
133
134 struct addrinfo hints;
135 struct addrinfo *result, *rp;
136 int sfd, s;
137
138 /* Obtain address(es) matching host/port */
139
140 memset(&hints, 0, sizeof(struct addrinfo));
141 hints.ai_family = AF_UNSPEC; /* Allow IPv4 or IPv6 */
142 hints.ai_socktype = SOCK_STREAM; /* stream socket */
143 hints.ai_flags = 0;
144 hints.ai_protocol = 0; /* Any protocol */
145
146#if (AX_TARGET_PLATFORM == AX_PLATFORM_WIN32)
147 WSADATA wsaData;
148 WSAStartup(MAKEWORD(2, 2), &wsaData);
149#endif
150
151 std::string nodeName;
152 if (Director::getInstance()->getConsole()->isIpv6Server())
153 nodeName = "::1";
154 else
155 nodeName = "localhost";
156
157 s = getaddrinfo(nodeName.c_str(), "5678", &hints, &result);
158 if (s != 0)
159 {
160 AXLOGD("ConsoleUploadFile: getaddrinfo error");
161 return;
162 }
163
164 /* getaddrinfo() returns a list of address structures.
165 Try each address until we successfully connect(2).
166 If socket(2) (or connect(2)) fails, we (close the socket
167 and) try the next address. */
168
169 for (rp = result; rp != nullptr; rp = rp->ai_next)
170 {
171 sfd = socket(rp->ai_family, rp->ai_socktype, rp->ai_protocol);
172 if (sfd == -1)
173 continue;
174
175 if (connect(sfd, rp->ai_addr, rp->ai_addrlen) != -1)
176 break; /* Success */
177
178#if defined(_WIN32)
179 closesocket(sfd);
180#else
181 close(sfd);

Callers

nothing calls this directly

Calls 10

getInstanceFunction · 0.85
closeFunction · 0.85
getDataFromFileMethod · 0.80
isNullMethod · 0.80
isIpv6ServerMethod · 0.80
getBytesMethod · 0.80
base64EncodeFunction · 0.50
freeFunction · 0.50
c_strMethod · 0.45
getSizeMethod · 0.45

Tested by

no test coverage detected