Skip to content
This repository was archived by the owner on Sep 13, 2020. It is now read-only.

Commit 03b47c7

Browse files
author
Damian Kowalewski
committed
Merge pull request #39 from mtl2034/master
Fix performance issues and prepare 1.0.1-rc3
2 parents 8b4bfd3 + 9af5938 commit 03b47c7

File tree

9 files changed

+71
-36
lines changed

9 files changed

+71
-36
lines changed

configure.ac

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
AC_INIT(parse-embedded, 1.0.1-rc2, damiank@fb.com)
1+
AC_INIT(parse-embedded, 1.0.1-rc3, damiank@fb.com)
22
AC_CONFIG_AUX_DIR(config)
33
AC_CONFIG_SRCDIR(common/simplejson.c)
44
AC_CONFIG_SRCDIR(unix/src/parse.c)
@@ -21,6 +21,18 @@ AC_CHECK_HEADERS(curl/curl.h)
2121
AC_CHECK_LIB(uuid, uuid_generate_random)
2222
AC_CHECK_HEADERS(uuid/uuid.h)
2323

24+
AC_CACHE_CHECK([whether getopt has optreset support],
25+
ac_cv_have_getopt_optreset, [
26+
AC_LINK_IFELSE([AC_LANG_PROGRAM([[
27+
#include <getopt.h>
28+
]], [[ extern int optreset; optreset = 0; ]])],[ ac_cv_have_getopt_optreset="yes" ],[ ac_cv_have_getopt_optreset="no"
29+
])
30+
])
31+
32+
if test "x$ac_cv_have_getopt_optreset" = "xyes" ; then
33+
AC_DEFINE(HAVE_OPTRESET, 1, [Define if optreset exists])
34+
fi
35+
2436
AC_ARG_ENABLE([yun],
2537
[ --enable-yun Enable Arduino Yun support],
2638
[case "${enableval}" in

openwrt/parse-embedded/Makefile

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@
1010
include $(TOPDIR)/rules.mk
1111

1212
PKG_NAME:=parse-embedded
13-
PKG_VERSION:=1.0.1-rc2
13+
PKG_VERSION:=1.0.1-rc3
1414
PKG_RELEASE:=1
1515

1616
PKG_SOURCE:=$(PKG_NAME)-sdks-$(PKG_VERSION).tar.gz

unix/yun/client.c

Lines changed: 27 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,6 @@
2020
*/
2121

2222
#include "client.h"
23-
#include <openssl/err.h>
2423

2524
int tcp_connect(const char *host, int port)
2625
{
@@ -41,7 +40,6 @@ int tcp_connect(const char *host, int port)
4140
if(connect(sock,(struct sockaddr *)&addr, sizeof(addr))<0) {
4241
return -1;
4342
}
44-
4543
return sock;
4644
}
4745

@@ -70,18 +68,36 @@ int tcp_write(int sock, char* data) {
7068
}
7169

7270
int tcp_read(int sock, char* data, int size, int timeout_sec) {
71+
struct timeval tv;
72+
fd_set receive;
7373
int n_recv = 0;
7474
int n_tmp = 0;
75-
struct timeval tv;
76-
tv.tv_sec = timeout_sec; // timeout
77-
tv.tv_usec = 0;
78-
setsockopt(sock, SOL_SOCKET, SO_RCVTIMEO, (char *)&tv,sizeof(struct timeval));
79-
while(n_recv < size && (n_tmp = recv(sock, data+n_recv, size-n_recv, 0)) > 0){
80-
if (n_tmp <= 0){
81-
//fprintf(stdout, "i:nothing to read\n");
82-
break;
75+
int bracketCount = 0;
76+
int readCount = 0;
77+
while(n_recv < size && readCount++ < timeout_sec * 10) {
78+
FD_ZERO(&receive);
79+
FD_SET(sock, &receive);
80+
tv.tv_sec = 0;
81+
tv.tv_usec = 100000;
82+
if(select(sock + 1, &receive, NULL, NULL, &tv) > 0) {
83+
if(FD_ISSET(sock, &receive)) {
84+
// need to put select to timeout asap
85+
n_tmp = recv(sock, data+n_recv, size-n_recv, 0);
86+
if (n_tmp == -1) {
87+
n_tmp = 0;
88+
}
89+
// Analyze the data to get the object asap.
90+
int i;
91+
for(i = 0; i < n_tmp; i ++) {
92+
if (data[n_recv + i] == '{') bracketCount++;
93+
if (data[n_recv + i] == '}') bracketCount--;
94+
}
95+
n_recv += n_tmp;
96+
if (n_recv > 0 && bracketCount == 0) {
97+
break;
98+
}
99+
}
83100
}
84-
n_recv += n_tmp;
85101
}
86102
data[n_recv] = '\0';
87103
return n_recv;

unix/yun/parse_request.c

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -179,8 +179,12 @@ int main(int argc , char **argv) {
179179
}
180180

181181
// process post init options
182+
#if defined(HAVE_OPTRESET)
182183
optreset = 1;
183184
optind = 1;
185+
#else
186+
optind = 0;
187+
#endif
184188

185189
while((c=getopt(argc,argv,":a:k:x:y:v:e:d:p:ish"))!=-1){
186190
switch(c){

unix/yun/yun.c

Lines changed: 21 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -29,52 +29,55 @@
2929
#include "utils.h"
3030
#include "yun.h"
3131

32-
char g_cAppID[APPLICATION_ID_MAX_LEN + 1];
33-
char g_cClientKey[CLIENT_KEY_MAX_LEN + 1];
34-
char g_cInstallationID[INSTALLATION_ID_MAX_LEN + 1];
35-
char g_cSessionToken[SESSION_TOKEN_MAX_LEN + 1];
32+
char g_cAppID[APPLICATION_ID_MAX_LEN + 1] = {0};
33+
char g_cClientKey[CLIENT_KEY_MAX_LEN + 1] = {0};
34+
char g_cInstallationID[INSTALLATION_ID_MAX_LEN + 1] ={0};
35+
char g_cSessionToken[SESSION_TOKEN_MAX_LEN + 1] = {0};
3636

3737
int yunReadProvisioningInfo() {
3838
int socketHandle = -1;
3939
char buf[128];
4040
char value[64];
41-
memset(value, 0, 64);
42-
if ((socketHandle = tcp_connect("127.0.0.1", 5700)) > 0) {
41+
if ((socketHandle = tcp_connect("localhost", 5700)) > 0) {
4342
// read appId
44-
memset(buf, 0, 128);
43+
memset(buf, 0, sizeof(buf));
44+
memset(value, 0, sizeof(value));
4545
tcp_write(socketHandle, "{\"command\": \"get\", \"key\": \"appId\"}\n");
46-
if (tcp_read(socketHandle, buf, 128, 2)) {
47-
getValueFromJSON(buf, "value", value, 64);
46+
if (tcp_read(socketHandle, buf, sizeof(buf) - 1, 2)) {
47+
getValueFromJSON(buf, "value", value, sizeof(value));
4848
if(strcmp("null", value) != 0) {
4949
strncpy(g_cAppID, value, sizeof(g_cAppID));
5050
}
5151
}
5252

5353
// read clientKey
54-
memset(buf, 0, 128);
54+
memset(buf, 0, sizeof(buf));
55+
memset(value, 0, sizeof(value));
5556
tcp_write(socketHandle, "{\"command\": \"get\", \"key\": \"clientKey\"}\n");
56-
if (tcp_read(socketHandle, buf, 128, 2)) {
57-
getValueFromJSON(buf, "value", value, 64);
57+
if (tcp_read(socketHandle, buf, sizeof(buf) - 1, 2)) {
58+
getValueFromJSON(buf, "value", value, sizeof(value));
5859
if(strcmp("null", value) != 0) {
5960
strncpy(g_cClientKey, value, sizeof(g_cClientKey));
6061
}
6162
}
6263

6364
// read installationId
64-
memset(buf, 0, 128);
65+
memset(buf, 0, sizeof(buf));
66+
memset(value, 0, sizeof(value));
6567
tcp_write(socketHandle, "{\"command\": \"get\", \"key\": \"installationId\"}\n");
66-
if (tcp_read(socketHandle, buf, 128, 2)) {
67-
getValueFromJSON(buf, "value", value, 64);
68+
if (tcp_read(socketHandle, buf, sizeof(buf) - 1, 2)) {
69+
getValueFromJSON(buf, "value", value, sizeof(value));
6870
if(strcmp("null", value) != 0) {
6971
strncpy(g_cInstallationID, value, sizeof(g_cInstallationID));
7072
}
7173
}
7274

7375
// read sessionToken
74-
memset(buf, 0, 128);
76+
memset(buf, 0, sizeof(buf));
77+
memset(value, 0, sizeof(value));
7578
tcp_write(socketHandle, "{\"command\": \"get\", \"key\": \"sessionToken\"}\n");
76-
if (tcp_read(socketHandle, buf, 128, 2)) {
77-
getValueFromJSON(buf, "value", value, 64);
79+
if (tcp_read(socketHandle, buf, sizeof(buf) - 1, 2)) {
80+
getValueFromJSON(buf, "value", value, sizeof(value));
7881
if(strcmp("null", value) != 0) {
7982
strncpy(g_cSessionToken, value, sizeof(g_cSessionToken));
8083
}

yun/libraries/Parse/examples/setup/Setup.ino

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
#include <Bridge.h>
22

3-
String revision = "1.0.1-rc2-1_ar71xx";
3+
String revision = "1.0.1-rc3-1_ar71xx";
44
String location = "https://raw.githubusercontent.com/ParsePlatform/parse-embedded-sdks/master/yun/linux_package/";
55

66
void downloadPackage(String file) {
10 KB
Binary file not shown.
12.7 KB
Binary file not shown.

yun/uploadLinuxPackage.sh

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -4,28 +4,28 @@ YUN_PWD=arduino #YUN's PASSWORD, default is arduino
44

55
# scp parse_push and parse_request to Yun
66
expect -c "
7-
spawn scp linux_package/parse-embedded_1.0.1-rc2-1_ar71xx.ipk root@$YUN_IP_ADDRESS:/root/
7+
spawn scp linux_package/parse-embedded_1.0.1-rc3-1_ar71xx.ipk root@$YUN_IP_ADDRESS:/root/
88
expect *password:
99
send $YUN_PWD\n
1010
interact
1111
"
1212

1313
expect -c "
14-
spawn scp linux_package/parse-embedded-yun_1.0.1-rc2-1_ar71xx.ipk root@$YUN_IP_ADDRESS:/root/
14+
spawn scp linux_package/parse-embedded-yun_1.0.1-rc3-1_ar71xx.ipk root@$YUN_IP_ADDRESS:/root/
1515
expect *password:
1616
send $YUN_PWD\n
1717
interact
1818
"
1919

2020
expect -c "
21-
spawn ssh root@$YUN_IP_ADDRESS ''/bin/opkg install /root/parse-embedded_1.0.1-rc2-1_ar71xx.ipk''
21+
spawn ssh root@$YUN_IP_ADDRESS ''/bin/opkg install /root/parse-embedded_1.0.1-rc3-1_ar71xx.ipk''
2222
expect *password:
2323
send $YUN_PWD\n
2424
interact
2525
"
2626

2727
expect -c "
28-
spawn ssh root@$YUN_IP_ADDRESS ''/bin/opkg install /root/parse-embedded-yun_1.0.1-rc2-1_ar71xx.ipk''
28+
spawn ssh root@$YUN_IP_ADDRESS ''/bin/opkg install /root/parse-embedded-yun_1.0.1-rc3-1_ar71xx.ipk''
2929
expect *password:
3030
send $YUN_PWD\n
3131
interact

0 commit comments

Comments
 (0)