Skip to content

Commit

Permalink
Merge branch 'main' into socketopt
Browse files Browse the repository at this point in the history
Change-Id: I0a750dd7cba9d268541d1f9b725b777f6a1740cf
  • Loading branch information
haozheng-cobalt committed Feb 22, 2024
2 parents a941b31 + e53d95b commit 6768676
Show file tree
Hide file tree
Showing 5 changed files with 22 additions and 21 deletions.
1 change: 1 addition & 0 deletions .github/workflows/main.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -63,6 +63,7 @@ jobs:
GITHUB_EVENT_NUMBER: ${{ github.event.number }}
if: |
github.event.action != 'labeled' ||
github.event.pull_request.merged == false &&
(
github.event.action == 'labeled' &&
github.event.label.name == 'runtest' ||
Expand Down
1 change: 1 addition & 0 deletions .github/workflows/main_win.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,7 @@ jobs:
# All triggers except draft PRs, unless PR is labeled with runtest
if: |
github.event.action != 'labeled' ||
github.event.pull_request.merged == false &&
(
github.event.action == 'labeled' &&
github.event.label.name == 'runtest' ||
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,6 @@
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.
#if SB_API_VERSION >= 16

#include <netinet/in.h>
#include <netinet/tcp.h>
Expand Down Expand Up @@ -76,7 +75,7 @@ TEST_P(PosixSocketSetOptionsTest, TryThemAllTCP) {
}

TEST_P(PosixSocketSetOptionsTest, TryThemAllUDP) {
int socket_fd = socket(GetSocketDomain(), SOCK_STREAM, IPPROTO_TCP);
int socket_fd = socket(GetSocketDomain(), SOCK_DGRAM, IPPROTO_UDP);

int true_val = 1;
EXPECT_EQ(setsockopt(socket_fd, SOL_SOCKET, SO_BROADCAST, &true_val,
Expand Down Expand Up @@ -127,4 +126,3 @@ INSTANTIATE_TEST_SUITE_P(PosixSocketAddressTypes,
} // namespace
} // namespace nplb
} // namespace starboard
#endif // SB_API_VERSION >= 16
26 changes: 8 additions & 18 deletions starboard/shared/win32/posix_emu/socket.cc
Original file line number Diff line number Diff line change
Expand Up @@ -83,26 +83,13 @@ static SOCKET handle_db_get(int fd, bool erase) {
extern "C" {

int sb_socket(int domain, int type, int protocol) {
// On Windows, we must call WSAStartup() before using any other socket
// functions, such as setsockopt, and call WSACleanup() when we are done using
// the Winsock library before exiting. Other platforms don't have similar
// functions to initialize/cleanup their socket libraries.
WSAData wsaData;
int init_result = WSAStartup(MAKEWORD(2, 2), &wsaData);
if (init_result != 0) {
SB_DLOG(ERROR) << "Failed to initialize WinSock, error = " << init_result;
WSACleanup();
return -1;
}

// Sockets on Windows do not use *nix-style file descriptors
// socket() returns a handle to a kernel object instead
SOCKET socket_handle = socket(domain, type, protocol);
if (socket_handle == INVALID_SOCKET) {
// TODO: update errno with file operation error
int last_error = WSAGetLastError();
SB_DLOG(ERROR) << "Failed to create socket, last_error = " << last_error;
WSACleanup();
return -1;
}

Expand All @@ -113,12 +100,10 @@ int close(int fd) {
SOCKET socket_handle = handle_db_get(fd, true);

if (socket_handle != INVALID_SOCKET) {
WSACleanup();
return closesocket(socket_handle);
}

// This is then a file handle, so use Windows `_close` API.
WSACleanup();
return _close(fd);
}

Expand All @@ -127,8 +112,14 @@ int sb_setsockopt(int socket,
int option_name,
const void* option_value,
int option_len) {
SOCKET socket_handle = handle_db_get(socket, false);

if (socket_handle != INVALID_SOCKET) {
return -1;
}

int result =
setsockopt(socket, level, option_name,
setsockopt(socket_handle, level, option_name,
reinterpret_cast<const char*>(option_value), option_len);
// TODO(b/321999529): Windows returns SOCKET_ERROR on failure. The specific
// error code can be retrieved by calling WSAGetLastError(), and Posix returns
Expand All @@ -138,8 +129,7 @@ int sb_setsockopt(int socket,
SB_DLOG(ERROR) << "Failed to set " << option_name << " on socket " << socket
<< ", last_error = " << last_error;
return -1;
} else {
return 0;
}
return 0;
}
} // extern "C"
11 changes: 11 additions & 0 deletions tools/metadata/validate.py
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,17 @@ def validate_content(textproto_content,
if warn_deprecations and len(third_party.url) > 0:
log.warning('"url" field is deprecated, please use "identifier" instead')

git_id = next((id for id in third_party.identifier if id.type == 'Git'), None)
if git_id:
subtree_dir = os.path.dirname(metadata_file_path).replace(os.sep, '/')
pattern = f'^git-subtree-dir: {subtree_dir}/*$'
log_format = '%(trailers:key=git-subtree-split,valueonly)'
args = ['git', 'log', '-1', f'--grep={pattern}', f'--pretty={log_format}']
p = subprocess.run(args, capture_output=True, text=True, check=True)
split = p.stdout.strip()
if split and git_id.version != split:
raise RuntimeError(f'{git_id.version} does not match {split}')


def validate_file(metadata_file_path, warn_deprecations=False):
logging.info('Validating %s', metadata_file_path)
Expand Down

0 comments on commit 6768676

Please sign in to comment.