Skip to content

Commit

Permalink
Add send and read timeout for sync task.
Browse files Browse the repository at this point in the history
  • Loading branch information
mobizt committed Apr 6, 2024
1 parent 7963df5 commit dcdc906
Show file tree
Hide file tree
Showing 10 changed files with 437 additions and 378 deletions.
4 changes: 2 additions & 2 deletions src/cloud_storage/CloudStorage.h
Original file line number Diff line number Diff line change
Expand Up @@ -587,8 +587,8 @@ class CloudStorage
String name, mime;
jut.addObject(name, "name", request.options->parent.getObject(), true, true);
jut.addObject(mime, "contentType", request.mime, true, true);
owriter.addMember(request.options->payload, name, "}");
owriter.addMember(request.options->payload, mime, "}");
owriter.addMember(request.options->payload, name, false, "}");
owriter.addMember(request.options->payload, mime, false, "}");
sData->request.file_data.multipart.setOptions(request.options->payload);
request.options->payload.remove(0, request.options->payload.length());
request.aClient->setFileContentLength(sData, sData->request.file_data.multipart.getOptions().length() + sData->request.file_data.multipart.getLast().length(), "Content-Length");
Expand Down
28 changes: 14 additions & 14 deletions src/cloud_storage/DataOptions.h
Original file line number Diff line number Diff line change
Expand Up @@ -330,27 +330,27 @@ namespace GoogleCloudStorage

// https://cloud.google.com/storage/docs/access-control/lists
// This value represents the item to add to an array.
InsertProperties &acl(const String &value) { return wr.append<InsertProperties &, String>(*this, value, buf, bufSize, buf[1], FPSTR(__func__)); }
InsertProperties &cacheControl(const String &value) { return wr.set<InsertProperties &, String>(*this, value, buf, bufSize, buf[2], FPSTR(__func__)); }
InsertProperties &contentDisposition(const String &value) { return wr.set<InsertProperties &, String>(*this, value, buf, bufSize, buf[3], FPSTR(__func__)); }
InsertProperties &contentEncoding(const String &value) { return wr.set<InsertProperties &, String>(*this, value, buf, bufSize, buf[4], FPSTR(__func__)); }
InsertProperties &contentLanguage(const String &value) { return wr.set<InsertProperties &, String>(*this, value, buf, bufSize, buf[5], FPSTR(__func__)); }
InsertProperties &contentType(const String &value) { return wr.set<InsertProperties &, String>(*this, value, buf, bufSize, buf[6], FPSTR(__func__)); }
InsertProperties &crc32c(const String &value) { return wr.set<InsertProperties &, String>(*this, value, buf, bufSize, buf[7], FPSTR(__func__)); }
InsertProperties &customTime(const String &value) { return wr.set<InsertProperties &, String>(*this, value, buf, bufSize, buf[8], FPSTR(__func__)); }
InsertProperties &eventBasedHold(bool value) { return wr.set<InsertProperties &, bool>(*this, value, buf, bufSize, buf[9], FPSTR(__func__)); }
InsertProperties &md5Hash(const String &value) { return wr.set<InsertProperties &, String>(*this, value, buf, bufSize, buf[10], FPSTR(__func__)); }
InsertProperties &acl(const String &value) { return wr.append<InsertProperties &, String>(*this, value, buf, bufSize, 1, FPSTR(__func__)); }
InsertProperties &cacheControl(const String &value) { return wr.set<InsertProperties &, String>(*this, value, buf, bufSize, 2, FPSTR(__func__)); }
InsertProperties &contentDisposition(const String &value) { return wr.set<InsertProperties &, String>(*this, value, buf, bufSize, 3, FPSTR(__func__)); }
InsertProperties &contentEncoding(const String &value) { return wr.set<InsertProperties &, String>(*this, value, buf, bufSize, 4, FPSTR(__func__)); }
InsertProperties &contentLanguage(const String &value) { return wr.set<InsertProperties &, String>(*this, value, buf, bufSize, 5, FPSTR(__func__)); }
InsertProperties &contentType(const String &value) { return wr.set<InsertProperties &, String>(*this, value, buf, bufSize, 6, FPSTR(__func__)); }
InsertProperties &crc32c(const String &value) { return wr.set<InsertProperties &, String>(*this, value, buf, bufSize, 7, FPSTR(__func__)); }
InsertProperties &customTime(const String &value) { return wr.set<InsertProperties &, String>(*this, value, buf, bufSize, 8, FPSTR(__func__)); }
InsertProperties &eventBasedHold(bool value) { return wr.set<InsertProperties &, bool>(*this, value, buf, bufSize, 9, FPSTR(__func__)); }
InsertProperties &md5Hash(const String &value) { return wr.set<InsertProperties &, String>(*this, value, buf, bufSize, 10, FPSTR(__func__)); }
InsertProperties &metadata(const object_t value)
{
buf[11] = FPSTR("{\"metadata\":{\"firebaseStorageDownloadTokens\":\"a82781ce-a115-442f-bac6-a52f7f63b3e8\"}}");
if (strlen(value.c_str()))
owriter.addMember(buf[11], value.c_str());
owriter.addMember(buf[11], value.c_str(), false);
owriter.getBuf(buf, bufSize);
return *this;
}
InsertProperties &retention(const object_t value) { return wr.set<InsertProperties &, object_t>(*this, value, buf, bufSize, buf[12], FPSTR(__func__)); }
InsertProperties &storageClass(const String &value) { return wr.set<InsertProperties &, String>(*this, value, buf, bufSize, buf[13], FPSTR(__func__)); }
InsertProperties &temporaryHold(bool value) { return wr.set<InsertProperties &, bool>(*this, value, buf, bufSize, buf[14], FPSTR(__func__)); }
InsertProperties &retention(const object_t value) { return wr.set<InsertProperties &, object_t>(*this, value, buf, bufSize, 12, FPSTR(__func__)); }
InsertProperties &storageClass(const String &value) { return wr.set<InsertProperties &, String>(*this, value, buf, bufSize, 13, FPSTR(__func__)); }
InsertProperties &temporaryHold(bool value) { return wr.set<InsertProperties &, bool>(*this, value, buf, bufSize, 14, FPSTR(__func__)); }
};

class Parent
Expand Down
89 changes: 53 additions & 36 deletions src/core/ObjectWriter.h
Original file line number Diff line number Diff line change
Expand Up @@ -38,20 +38,31 @@ class ObjectWriter
JSONUtil jut;

public:
void addMember(String &buf, const String &v, const String &token = "}}")
void addMember(String &buf, const String &v, bool isString, const String &token = "}}")
{
int p = buf.lastIndexOf(token);
String str = buf.substring(0, p);
str += ',';
// Add to object
if (token[0] == '}')
{
String tmp = v;
String tmp;
if (isString)
tmp += '"';
tmp += v;
if (isString)
tmp += '"';
str += tmp.substring(1, tmp.length() - 1);
}
// Add to array
else
{
if (isString)
str += '"';
str += v;
if (isString)
str += '"';
}
str += token;
buf = str;
}
Expand All @@ -65,22 +76,25 @@ class ObjectWriter
if (buf.length() == 0)
buf = object;
else
addMember(buf, object, token);
addMember(buf, object, false, token);
}
}

void addMapArrayMember(String *buf, size_t size, String &buf_n, const String &key, const String &memberValue, bool isString)
void addMapArrayMember(String *buf, size_t size, uint8_t index, const String &key, const String &memberValue, bool isString)
{
if (buf_n.length() == 0)
if (index < size)
{
String temp;
jut.addArray(temp, memberValue, isString, true);
jut.addObject(buf_n, key, temp, false, true);
}
else
addMember(buf_n, isString ? jut.toString(memberValue) : memberValue, "]}");
if (buf[index].length() == 0)
{
String temp;
jut.addArray(temp, memberValue, isString, true);
jut.addObject(buf[index], key, temp, false, true);
}
else
addMember(buf[index], memberValue, isString, "]}");

getBuf(buf, size);
getBuf(buf, size);
}
}

void getBuf(String *buf, size_t size)
Expand All @@ -90,14 +104,17 @@ class ObjectWriter
addObject(buf[0], buf[i], "}", i == 0);
}

void setObject(String *buf, size_t size, String &buf_n, const String &key, const String &value, bool isString, bool last)
void setObject(String *buf, size_t size, uint8_t index, const String &key, const String &value, bool isString, bool last)
{
if (key.length())
if (index < size)
{
clear(buf_n);
jut.addObject(buf_n, key, value, isString, last);
if (key.length())
{
clear(buf[index]);
jut.addObject(buf[index], key, value, isString, last);
}
getBuf(buf, size);
}
getBuf(buf, size);
}

void clearBuf(String *buf, size_t size)
Expand Down Expand Up @@ -171,9 +188,9 @@ class BufWriter
static bool const value = std::is_same<T, const char *>::value || std::is_same<T, std::string>::value || std::is_same<T, String>::value;
};

void setObject(String *buf, size_t bufSize, String &buf_n, const String &key, const String &value, bool isString, bool last)
void setObject(String *buf, size_t bufSize, uint8_t index, const String &key, const String &value, bool isString, bool last)
{
owriter.setObject(buf, bufSize, buf_n, key, value, isString, last);
owriter.setObject(buf, bufSize, index, key, value, isString, last);
}

public:
Expand Down Expand Up @@ -211,58 +228,58 @@ class BufWriter
}

template <typename T1, typename T2>
T1 set(T1 ret, bool value, String *buf, size_t bufSize, String &buf_n, const String &name)
T1 set(T1 ret, bool value, String *buf, size_t bufSize, uint8_t index, const String &name)
{
setObject(buf, bufSize, buf_n, name, owriter.getBoolStr(value), false, true);
setObject(buf, bufSize, index, name, owriter.getBoolStr(value), false, true);
return ret;
}

template <typename T1, typename T2>
auto set(T1 ret, const T2 &value, String *buf, size_t bufSize, String &buf_n, const String &name) -> typename std::enable_if<v_number<T2>::value, T1>::type
auto set(T1 ret, const T2 &value, String *buf, size_t bufSize, uint8_t index, const String &name) -> typename std::enable_if<v_number<T2>::value, T1>::type
{
setObject(buf, bufSize, buf_n, name, String(value), false, true);
setObject(buf, bufSize, index, name, String(value), false, true);
return ret;
}

template <typename T1, typename T2>
auto set(T1 ret, const T2 &value, String *buf, size_t bufSize, String &buf_n, const String &name) -> typename std::enable_if<v_sring<T2>::value, T1>::type
auto set(T1 ret, const T2 &value, String *buf, size_t bufSize, uint8_t index, const String &name) -> typename std::enable_if<v_sring<T2>::value, T1>::type
{
setObject(buf, bufSize, buf_n, name, value, true, true);
setObject(buf, bufSize, index, name, value, true, true);
return ret;
}

template <typename T1, typename T2>
auto set(T1 ret, const T2 &value, String *buf, size_t bufSize, String &buf_n, const String &name) -> typename std::enable_if<(!v_sring<T2>::value && !v_number<T2>::value && !std::is_same<T2, bool>::value), T1>::type
auto set(T1 ret, const T2 &value, String *buf, size_t bufSize, uint8_t index, const String &name) -> typename std::enable_if<(!v_sring<T2>::value && !v_number<T2>::value && !std::is_same<T2, bool>::value), T1>::type
{
setObject(buf, bufSize, buf_n, name, value.c_str(), false, true);
setObject(buf, bufSize, index, name, value.c_str(), false, true);
return ret;
}

template <typename T1, typename T2>
T1 append(T1 ret, bool value, String *buf, size_t bufSize, String &buf_n, const String &name)
T1 append(T1 ret, bool value, String *buf, size_t bufSize, uint8_t index, const String &name)
{
owriter.addMapArrayMember(buf, bufSize, buf_n, name, owriter.getBoolStr(value), false);
owriter.addMapArrayMember(buf, bufSize, index, name, owriter.getBoolStr(value), false);
return ret;
}

template <typename T1, typename T2>
auto append(T1 ret, const T2 &value, String *buf, size_t bufSize, String &buf_n, const String &name) -> typename std::enable_if<v_number<T2>::value, T1>::type
auto append(T1 ret, const T2 &value, String *buf, size_t bufSize, uint8_t index, const String &name) -> typename std::enable_if<v_number<T2>::value, T1>::type
{
owriter.addMapArrayMember(buf, bufSize, buf_n, name, String(value), false);
owriter.addMapArrayMember(buf, bufSize, index, name, String(value), false);
return ret;
}

template <typename T1, typename T2>
auto append(T1 ret, const T2 &value, String *buf, size_t bufSize, String &buf_n, const String &name) -> typename std::enable_if<v_sring<T2>::value, T1>::type
auto append(T1 ret, const T2 &value, String *buf, size_t bufSize, uint8_t index, const String &name) -> typename std::enable_if<v_sring<T2>::value, T1>::type
{
owriter.addMapArrayMember(buf, bufSize, buf_n, name, value, true);
owriter.addMapArrayMember(buf, bufSize, index, name, value, true);
return ret;
}

template <typename T1, typename T2>
auto append(T1 ret, const T2 &value, String *buf, size_t bufSize, String &buf_n, const String &name) -> typename std::enable_if<(!v_sring<T2>::value && !v_number<T2>::value && !std::is_same<T2, bool>::value), T1>::type
auto append(T1 ret, const T2 &value, String *buf, size_t bufSize, uint8_t index, const String &name) -> typename std::enable_if<(!v_sring<T2>::value && !v_number<T2>::value && !std::is_same<T2, bool>::value), T1>::type
{
owriter.addMapArrayMember(buf, bufSize, buf_n, name, value.c_str(), false);
owriter.addMapArrayMember(buf, bufSize, index, name, value.c_str(), false);
return ret;
}
void clear(String &buf) { buf.remove(0, buf.length()); }
Expand Down Expand Up @@ -479,7 +496,7 @@ namespace firebase

class UnityRange
{
public:
public:
UnityRange() {}

float val(float value)
Expand Down
Loading

0 comments on commit dcdc906

Please sign in to comment.