138 Data srcFileData = FileUtils::getInstance()->getDataFromFile(
s_pathGrossini);
139 if (srcFileData.isNull())
141 CCLOGERROR(
"ConsoleUploadFile: could not open file %s",
s_pathGrossini);
146 struct addrinfo hints;
147 struct addrinfo *result, *rp;
152 memset(&hints, 0,
sizeof(
struct addrinfo));
153 hints.ai_family = AF_UNSPEC;
154 hints.ai_socktype = SOCK_STREAM;
156 hints.ai_protocol = 0;
158#if (CC_TARGET_PLATFORM == CC_PLATFORM_WIN32)
160 WSAStartup(MAKEWORD(2, 2),&wsaData);
163 std::string nodeName;
164 if (Director::getInstance()->getConsole()->isIpv6Server())
167 nodeName =
"localhost";
169 s = getaddrinfo(nodeName.c_str(),
"5678", &hints, &result);
172 CCLOG(
"ConsoleUploadFile: getaddrinfo error");
181 for (rp = result; rp !=
nullptr; rp = rp->ai_next) {
182 sfd = socket(rp->ai_family, rp->ai_socktype,
187 if (connect(sfd, rp->ai_addr, rp->ai_addrlen) != -1)
190#if (CC_TARGET_PLATFORM == CC_PLATFORM_WIN32)
198 CCLOG(
"ConsoleUploadFile: could not connect!");
202 freeaddrinfo(result);
204 std::string tmp =
"upload";
207 tmp += targetFileName;
211 strcpy(cmd, tmp.c_str());
212 send(sfd,cmd,strlen(cmd),0);
215 auto readBuffer = [&offset](
char* buf,
size_t bytes,
const Data& data) -> ssize_t {
216 if (offset >= data.getSize())
218 ssize_t actualReadBytes = (offset + bytes) > data.getSize() ? (data.getSize() - offset) : bytes;
219 if (actualReadBytes > 0)
221 memcpy(buf, data.getBytes() + offset, actualReadBytes);
222 offset += actualReadBytes;
224 return actualReadBytes;
229 char buffer[3], *out;
231 in = (
unsigned char *)buffer;
233 ssize_t ret = readBuffer(buffer, 3, srcFileData);
236 int len = base64Encode(in, (
unsigned int)ret, &out);
237 send(sfd, out, len, 0);
242 log(
"Reach the end, total send: %d bytes", (
int)offset);
256 std::this_thread::sleep_for(std::chrono::seconds(1));
258#if (CC_TARGET_PLATFORM == CC_PLATFORM_WIN32)
static const char s_pathGrossini[]