Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

SocketWrapper MbedClient debugging readSocket#912

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to ourterms of service andprivacy statement. We’ll occasionally send you account related emails.

Already on GitHub?Sign in to your account

Open
JAndrassy wants to merge1 commit intoarduino:main
base:main
Choose a base branch
Loading
fromJAndrassy:mbedclient_readsocket_fixes
Open
Changes fromall commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
33 changes: 24 additions & 9 deletionslibraries/SocketWrapper/src/MbedClient.cpp
View file
Open in desktop
Original file line numberDiff line numberDiff line change
Expand Up@@ -22,28 +22,30 @@ void arduino::MbedClient::readSocket() {
int ret = NSAPI_ERROR_WOULD_BLOCK;
do {
mutex->lock();
if (sock != nullptr && rxBuffer.availableForStore() == 0) {
if (sock == nullptr) {
Copy link

@schnoberts1schnoberts1Sep 9, 2024
edited
Loading

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others.Learn more.

Is this subject to the same issues as "Another racy example" here:https://queue.acm.org/detail.cfm?id=2088916? sock is loop invariant but changed in another thread. mutex is the same isn't it?

mutex->unlock();
goto cleanup;
}
if (rxBuffer.availableForStore() == 0) {
mutex->unlock();
yield();
continue;
} else if (sock == nullptr) {
goto cleanup;
}
ret = sock->recv(data, rxBuffer.availableForStore());
if (ret < 0 && ret != NSAPI_ERROR_WOULD_BLOCK) {
mutex->unlock();
goto cleanup;
}
if (ret == NSAPI_ERROR_WOULD_BLOCK || ret == 0) {
yield();
mutex->unlock();
continue;
break;
}
for (int i = 0; i < ret; i++) {
rxBuffer.store_char(data[i]);
}
mutex->unlock();
_status = true;
} while (ret == NSAPI_ERROR_WOULD_BLOCK || ret > 0);
} while (true);
}
cleanup:
_status = false;
Expand DownExpand Up@@ -98,6 +100,7 @@ int arduino::MbedClient::connect(SocketAddress socketAddress) {
}

if (static_cast<TCPSocket *>(sock)->open(getNetwork()) != NSAPI_ERROR_OK) {
_status = false;
return 0;
}

Expand All@@ -117,6 +120,7 @@ int arduino::MbedClient::connect(SocketAddress socketAddress) {
configureSocket(sock);
_status = true;
} else {
sock->close();
_status = false;
}

Expand DownExpand Up@@ -148,6 +152,7 @@ int arduino::MbedClient::connectSSL(SocketAddress socketAddress) {
}

if (static_cast<TLSSocket *>(sock)->open(getNetwork()) != NSAPI_ERROR_OK) {
_status = false;
return 0;
}

Expand DownExpand Up@@ -179,6 +184,7 @@ int arduino::MbedClient::connectSSL(SocketAddress socketAddress) {
configureSocket(sock);
_status = true;
} else {
sock->close();
_status = false;
}

Expand DownExpand Up@@ -224,8 +230,9 @@ int arduino::MbedClient::available() {
}

int arduino::MbedClient::read() {
if (sock == nullptr)
if (mutex == nullptr) {
return -1;
}
mutex->lock();
if (!available()) {
mutex->unlock();
Expand All@@ -238,8 +245,9 @@ int arduino::MbedClient::read() {
}

int arduino::MbedClient::read(uint8_t *data, size_t len) {
if (sock == nullptr)
if (mutex == nullptr) {
return 0;
}
mutex->lock();
int avail = available();

Expand All@@ -261,7 +269,14 @@ int arduino::MbedClient::read(uint8_t *data, size_t len) {
}

int arduino::MbedClient::peek() {
return rxBuffer.peek();
if (mutex == nullptr) {
return 0;
}
mutex->lock();
int res = rxBuffer.peek();
mutex->unlock();

return res;
}

void arduino::MbedClient::flush() {
Expand Down

[8]ページ先頭

©2009-2025 Movatter.jp