Skip to content
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 our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Codechange: [Network] split CloseSocket and CloseConnection more clearly #9261

Merged
merged 2 commits into from May 13, 2021

Conversation

TrueBrain
Copy link
Member

Motivation / Problem

During work on the Network code I kept hitting a problem: I got totally confused with Close vs CloseConnection.

Turns out: its not me!

Depending on the file you look at, it has a different meaning.

Yippie!

Lets add some sanity to the code, shall we?

Description

There should be no functional difference with this PR.

Simple new rules:

  • CloseSocket -> Closes the OS socket
  • CloseConnection -> TCP only, cleans up the connection (but leaves the socket open)
  • MarkClosed -> Only meant to hint the socket is closed. Mainly used to not make this have any functional change.

As added bonus, the dtors are a lot easier to understand now too.

Limitations

Checklist for review

Some things are not automated, and forgotten often. This list is a reminder for the reviewers.

  • The bug fix is important enough to be backported? (label: 'backport requested')
  • This PR affects the save game format? (label 'savegame upgrade')
  • This PR affects the GS/AI API? (label 'needs review: Script API')
    • ai_changelog.hpp, gs_changelog.hpp need updating.
    • The compatibility wrappers (compat_*.nut) need updating.
  • This PR affects the NewGRF API? (label 'needs review: NewGRF')

Although there is no other path that destroys ClientNetworkGameSocketHandler
it still feels weird to do it outside the dtor. If future-work
changes anything here, we all of a sudden leak memory.
@TrueBrain TrueBrain changed the title Codechange: [Network] split CloseSocket and CloseConnection more clear Codechange: [Network] split CloseSocket and CloseConnection more clearly May 13, 2021
src/network/core/tcp_http.cpp Outdated Show resolved Hide resolved
src/network/core/udp.h Outdated Show resolved Hide resolved
src/network/core/udp.h Outdated Show resolved Hide resolved
src/network/core/tcp.cpp Outdated Show resolved Hide resolved
src/network/core/tcp.cpp Outdated Show resolved Hide resolved
src/network/core/tcp.h Outdated Show resolved Hide resolved
- CloseSocket now closes the actual OS socket.
- CloseConnection frees up the resources to just before CloseSocket.
- dtors call CloseSocket / CloseConnection where needed.
@TrueBrain TrueBrain merged commit a403653 into OpenTTD:master May 13, 2021
@TrueBrain TrueBrain deleted the fix-close-connection branch May 13, 2021 09:46
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

2 participants