+ OIC_LOG(INFO, TAG, "connect socket success");
+ svritem->state = CONNECTED;
+ CHECKFD(svritem->fd);
+ ssize_t len = CAWakeUpForReadFdsUpdate(svritem->sep.endpoint.addr);
+ if (-1 == len)
+ {
+ OIC_LOG(ERROR, TAG, "wakeup receive thread failed");
+ return CA_SOCKET_OPERATION_FAILED;
+ }
+
+#if defined(__TIZEN__)
+ // #5. Send HTTP CONNECT to proxy if proxy
+
+ const char *cloud_address = CAGetCloudAddressForProxy();
+ OIC_LOG_V(INFO, TAG, "Proxy : '%s'", cloud_address ? cloud_address : "(nil)");
+
+ if(cloud_address && *cloud_address)
+ {
+ char message[4096];
+ int len = sprintf(message,
+ "CONNECT %s HTTP/1.1\r\n"
+ "Host: %s\r\n\r\n", cloud_address, cloud_address
+ );
+
+ ssize_t l = send(fd, message, len, 0);
+ if(l != len)
+ {
+ OIC_LOG_V(ERROR, TAG, "failed to send HTTP CONNECT data (expected %d bytes, ret %d)", len, l);
+ close(fd);
+ svritem->fd = -1;
+ return CA_SOCKET_OPERATION_FAILED;
+ }
+
+ // maybe this should be called in other thread, it causes bottleneck.
+ OIC_LOG_V(INFO, TAG, "Message sent is : '%s'\n", message);
+
+ *message = '\0';
+ OIC_LOG_V(INFO, TAG, "Receiving response to CONNECT from proxy...");
+
+ l = recv(fd, message, 4096, 0);
+
+ OIC_LOG_V(INFO, TAG, "Received data : '%s'", message);
+ OIC_LOG_V(INFO, TAG, "Received len = %d", l);
+
+ int status_code = CAGetHTTPStatusCode(message);
+
+ OIC_LOG_V(INFO, TAG, "HTTP status_code : %d", status_code);
+ if(status_code < 200 || status_code > 299)
+ {
+ OIC_LOG_V(ERROR, TAG, "Error, Wrong status code: %d", status_code);
+ close(fd);
+ svritem->fd = -1;
+ return CA_SOCKET_OPERATION_FAILED;
+ }
+ }
+#endif
+
+ return CA_STATUS_OK;