Skip to content

Commit

Permalink
Fixes for #108
Browse files Browse the repository at this point in the history
  • Loading branch information
nkolban committed Oct 7, 2017
1 parent 2330db8 commit f9d7d31
Show file tree
Hide file tree
Showing 4 changed files with 33 additions and 1 deletion.
6 changes: 5 additions & 1 deletion cpp_utils/tests/test_rest.cpp
Expand Up @@ -2,6 +2,10 @@
* Test the REST API client.
* This application leverages LibCurl. You must make that package available
* as well as "enable it" from "make menuconfig" and C++ Settings -> libCurl present.
*
* You may also have to include "posix_shims.c" in your compilation to provide resolution
* for Posix calls expected by libcurl that aren't present in ESP-IDF.
*
* See also:
* * https://github.com/nkolban/esp32-snippets/issues/108
*
Expand Down Expand Up @@ -37,7 +41,7 @@ class CurlTestTask: public Task {

RESTTimings *timings = client.getTimings();

client.setURL("https://httpbin.org/post");
client.setURL("http://httpbin.org/post");
client.addHeader("Content-Type", "application/json");
client.post("hello world!");
ESP_LOGD(tag, "Result: %s", client.getResponse().c_str());
Expand Down
2 changes: 2 additions & 0 deletions curl/README.md
@@ -0,0 +1,2 @@
## Missing Posix functions
LibCurl is a moving target and on occassion, is updated to utilize functions that are not part of the ESP-IDF. For example, at the time of writing, the latest version of LibCurl uses the Posix `access(2)` system call that it previously did not. This call is not present in ESP-IDF. To circumvent the problem, a shim file has been provided in `./posix/posix_shims.c` that provides simple implementations for some missing Posix functions.
8 changes: 8 additions & 0 deletions posix/README.md
@@ -0,0 +1,8 @@
# POSIX
Posix is the specification for Unix like functions. The ESP-IDF provides many implementations for Posix functions but some are omitted and thus should not be used in ESP32 based applications. However there are times when we received 3rd party code that uses a Posix function that we don't have in our environment. Our choices then become:

* Contact the 3rd party provider and ask them to alter their code to remove it, replace it or make it optional.
* Contact Espressif and ask them to add support for the missing Posix function.
* Provide a shim that satisfies the Posix function using the capabailities that are available to us.

In the source file called `posix_shims.c` we provide some of those shims.
18 changes: 18 additions & 0 deletions posix/posix_shims.c
@@ -0,0 +1,18 @@
#include <unistd.h>
#include <errno.h>
#include <sys/stat.h>

/**
* @brief Provide a shim for the Posix access(2) function.
* @param [in] pathname The file to check.
* @param [in] mode The mode of access requested.
* @return 0 on success, -1 on error with errno set.
*/
int access(const char *pathname, int mode) {
struct stat statBuf;
if (stat(pathname, &statBuf) == -1) {
errno = ENOENT;
return -1;
}
return 0; // Indicate that all we have access to the file.
} // access

0 comments on commit f9d7d31

Please sign in to comment.