RFC: NetworkInterfaces implementation

Tom Tromey tromey@redhat.com
Fri Aug 16 09:47:00 GMT 2002


>>>>> "Michael" == Michael Koch <konqueror@gmx.de> writes:

Michael> I have writtenn a little rough implementation of the class
Michael> java.net.NetworkInterfaces. Its not yet ready, nor fully
Michael> implemented. I just post here for comments.
I haven't read the docs on this class. I do have some style notes.
Overall this code is looking good to me.
Michael> public final class NetworkInterface extends Object
Don't write `extends Object'. There's no need.
Could you write javadoc for the class? These days we prefer to have it.
Michael> if (s != null)
Michael> {
Michael> // TODO: implement the usage of security manager
Michael> }
Ordinarily we use FIXME instead of TODO. Is implementing this check
hard? I know we're pretty inconsistent about implementing these
checks right now, but I'd like to change that.
Michael> if (tmp.getName() == name)
Michael> return tmp;
Do you really want == here and not equals()?
Michael> for (Enumeration interfaces = networkInterfaces.elements(); interfaces.hasMoreElements();)
Michael> {
Here the indentation is subtly off: the open brace must be indented
two spaces relative to the `for'. Also long lines (>= 80 characters)
should be wrapped at a logical place, so for instance the `for' line
should probably be wrapped just after the `;' that comes before the
update expression.
Michael> // TODO: add configure check for this
Michael> #include <net/if.h>
This check has to be done before this can go in.
Michael> // open socket
Comments must be full sentences: start with a capital letter, end with
a period.
Michael> if (fd >= 0)
Michael> {
Again the brace must go in 2 spaces. If you use Emacs and have
cc-mode set up correctly you can just have Emacs reindent these files
automatically. I can try to dig up the settings if you're interested.
Michael> if (::ioctl(fd, SIOCGIFCONF, &if_data) < 0)
Michael> goto out;
We need some kind of configure wrapper for this code. Basically, if
we don't have this capability we ought to just use the default
implementation of returning an empty vector. (Unless throwing an
exception is more appropriate -- what do you think?)
You should use _Jv_Realloc instead of realloc.
You must make sure to free memory allocated with _Jv_Realloc before
returning. Right now the code doesn't do that.
Should the code throw an exception if ioctl fails?
I notice that if the ioctl fails then the file descriptor is never
closed. I think the code should be very defensive here and even make
sure to catch any exceptions that might be thrown by the various
library calls so that the cleanups will always be run.
Do the various methods that check and modify networkInterfaces need to
be synchronized?
What is your paperwork status? In order to accept a contribution of
this size we'll need you to sign the legal papers. If you don't have
paperwork, tell me and I'll figure out how to get things started.
Tom


More information about the Java mailing list

AltStyle によって変換されたページ (->オリジナル) /