Skip to content

Commit f9d7d31

Browse files
committed
Fixes for nkolban#108
1 parent 2330db8 commit f9d7d31

File tree

4 files changed

+33
-1
lines changed

4 files changed

+33
-1
lines changed

cpp_utils/tests/test_rest.cpp

+5-1
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,10 @@
22
* Test the REST API client.
33
* This application leverages LibCurl. You must make that package available
44
* as well as "enable it" from "make menuconfig" and C++ Settings -> libCurl present.
5+
*
6+
* You may also have to include "posix_shims.c" in your compilation to provide resolution
7+
* for Posix calls expected by libcurl that aren't present in ESP-IDF.
8+
*
59
* See also:
610
* * https://github.com/nkolban/esp32-snippets/issues/108
711
*
@@ -37,7 +41,7 @@ class CurlTestTask: public Task {
3741

3842
RESTTimings *timings = client.getTimings();
3943

40-
client.setURL("https://httpbin.org/post");
44+
client.setURL("http://httpbin.org/post");
4145
client.addHeader("Content-Type", "application/json");
4246
client.post("hello world!");
4347
ESP_LOGD(tag, "Result: %s", client.getResponse().c_str());

curl/README.md

+2
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
## Missing Posix functions
2+
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.

posix/README.md

+8
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
# POSIX
2+
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:
3+
4+
* Contact the 3rd party provider and ask them to alter their code to remove it, replace it or make it optional.
5+
* Contact Espressif and ask them to add support for the missing Posix function.
6+
* Provide a shim that satisfies the Posix function using the capabailities that are available to us.
7+
8+
In the source file called `posix_shims.c` we provide some of those shims.

posix/posix_shims.c

+18
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
#include <unistd.h>
2+
#include <errno.h>
3+
#include <sys/stat.h>
4+
5+
/**
6+
* @brief Provide a shim for the Posix access(2) function.
7+
* @param [in] pathname The file to check.
8+
* @param [in] mode The mode of access requested.
9+
* @return 0 on success, -1 on error with errno set.
10+
*/
11+
int access(const char *pathname, int mode) {
12+
struct stat statBuf;
13+
if (stat(pathname, &statBuf) == -1) {
14+
errno = ENOENT;
15+
return -1;
16+
}
17+
return 0; // Indicate that all we have access to the file.
18+
} // access

0 commit comments

Comments
 (0)