-
-
Notifications
You must be signed in to change notification settings - Fork 1.6k
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
✨ std: System.hostname #2649
✨ std: System.hostname #2649
Conversation
Reading the specs, I also think at some point soon it may make sense to split the specs up into subdirs so as to keep them focused on segments of the |
# Maximum of 253 characters are allowed, with 2 bytes reserved for storage. | ||
# In practice, many platforms will disallow anything longer than 63 characters. | ||
# ``` | ||
# Socket.gethostname # => my.machine.name.local |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Socket.gethostname # => "host.example.org"
It returns a string and using an mDNS name for your stuff will probably break things, so not a good example IMO ;)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Derp, fixing example.
f690534
to
e2c2b57
Compare
I believe it would be better for the name to be |
@lbguilherme That might make sense, how would that relate to a scenario in which someone is setting a hostname? Unless we think that The latter seems more confusing to me. |
Perhaps Another name I can think of is |
In any case, this functionality is blocking and maybe it should be non-blocking (use libevent, or some other mechanism), so this will have to wait untli @waj can approve this (he's on vacations for a few weeks now) |
@asterite It is a blocking system call, but it is not network dependent. It simply reads system configuration. It should usually be the same as the |
@jhass Oh, my mistake, I confused this with something like I agree that Go also has So maybe
Well, Process is certainly different than Processor, and |
POSIX words it as
I don't like it on |
|
I see this as my first foray into LibC here, so wanted to get the On Thu, May 26, 2016, 09:54 Ary Borenszweig notifications@github.com
|
OK, let's use I was planning on releasing 0.17.4 today, which contains a few goodies and many fixes. I'd like to include this too because it's backwards compatible and generally useful. We have to create a We have these options:
|
e2c2b57
to
5c6800c
Compare
@@ -0,0 +1,20 @@ | |||
require "c/sys/socket" | |||
|
|||
class System |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
module
;)
New class for System-related functions. First: method to retrieve the current hostname.
5c6800c
to
aee43c2
Compare
@asterite I've updated the PR, let's hope CI doesn't bite me. :)
I'm happy to send a PR to any branch you like. |
@miketheman Thanks! Order used to matter, but now it matters less and less. It only matters if macros are used (macros need to be defined before they are used), but a first compiler pass gathers all classes and methods, so in this case it's OK to put it in any order. |
It seems libevent requires c/netdb, which in turns requires |
@asterite awesome - I think I'll add a note to prelude.cr in another PR about ordering. For this one, all tests pass, the world didn't explode, is there any further steps? |
No, thank you! |
Woohoo, thanks! |
Addition of a method to retrieve the current hostname.
Hat tip to @jhass for showing the example on the mailing list.
I was unable to figure out a method for testing a hostname longer than 255 chars without creating the
sethostname
method, and didn't want to implement two things at once before I know if this is the correct approach.The notation in
src/lib_c/<platform>/c/sys/socket.cr
is a little inconsistent across platforms - some usexN
, others usefd
- so I followed my gut and use descriptive notation for all platforms.