Leaked source code of windows server 2003
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

143 lines
3.2 KiB

  1. # IO::Socket::UNIX.pm
  2. #
  3. # Copyright (c) 1997-8 Graham Barr <[email protected]>. All rights reserved.
  4. # This program is free software; you can redistribute it and/or
  5. # modify it under the same terms as Perl itself.
  6. package IO::Socket::UNIX;
  7. use strict;
  8. our(@ISA, $VERSION);
  9. use IO::Socket;
  10. use Socket;
  11. use Carp;
  12. @ISA = qw(IO::Socket);
  13. $VERSION = "1.20";
  14. IO::Socket::UNIX->register_domain( AF_UNIX );
  15. sub new {
  16. my $class = shift;
  17. unshift(@_, "Peer") if @_ == 1;
  18. return $class->SUPER::new(@_);
  19. }
  20. sub configure {
  21. my($sock,$arg) = @_;
  22. my($bport,$cport);
  23. my $type = $arg->{Type} || SOCK_STREAM;
  24. $sock->socket(AF_UNIX, $type, 0) or
  25. return undef;
  26. if(exists $arg->{Local}) {
  27. my $addr = sockaddr_un($arg->{Local});
  28. $sock->bind($addr) or
  29. return undef;
  30. }
  31. if(exists $arg->{Listen} && $type != SOCK_DGRAM) {
  32. $sock->listen($arg->{Listen} || 5) or
  33. return undef;
  34. }
  35. elsif(exists $arg->{Peer}) {
  36. my $addr = sockaddr_un($arg->{Peer});
  37. $sock->connect($addr) or
  38. return undef;
  39. }
  40. $sock;
  41. }
  42. sub hostpath {
  43. @_ == 1 or croak 'usage: $sock->hostpath()';
  44. my $n = $_[0]->sockname || return undef;
  45. (sockaddr_un($n))[0];
  46. }
  47. sub peerpath {
  48. @_ == 1 or croak 'usage: $sock->peerpath()';
  49. my $n = $_[0]->peername || return undef;
  50. (sockaddr_un($n))[0];
  51. }
  52. 1; # Keep require happy
  53. __END__
  54. =head1 NAME
  55. IO::Socket::UNIX - Object interface for AF_UNIX domain sockets
  56. =head1 SYNOPSIS
  57. use IO::Socket::UNIX;
  58. =head1 DESCRIPTION
  59. C<IO::Socket::UNIX> provides an object interface to creating and using sockets
  60. in the AF_UNIX domain. It is built upon the L<IO::Socket> interface and
  61. inherits all the methods defined by L<IO::Socket>.
  62. =head1 CONSTRUCTOR
  63. =over 4
  64. =item new ( [ARGS] )
  65. Creates an C<IO::Socket::UNIX> object, which is a reference to a
  66. newly created symbol (see the C<Symbol> package). C<new>
  67. optionally takes arguments, these arguments are in key-value pairs.
  68. In addition to the key-value pairs accepted by L<IO::Socket>,
  69. C<IO::Socket::UNIX> provides.
  70. Type Type of socket (eg SOCK_STREAM or SOCK_DGRAM)
  71. Local Path to local fifo
  72. Peer Path to peer fifo
  73. Listen Create a listen socket
  74. If the constructor is only passed a single argument, it is assumed to
  75. be a C<Peer> specification.
  76. NOTE NOTE NOTE NOTE NOTE NOTE NOTE NOTE NOTE NOTE NOTE NOTE
  77. As of VERSION 1.18 all IO::Socket objects have autoflush turned on
  78. by default. This was not the case with earlier releases.
  79. NOTE NOTE NOTE NOTE NOTE NOTE NOTE NOTE NOTE NOTE NOTE NOTE
  80. =back
  81. =head1 METHODS
  82. =over 4
  83. =item hostpath()
  84. Returns the pathname to the fifo at the local end
  85. =item peerpath()
  86. Returns the pathanme to the fifo at the peer end
  87. =back
  88. =head1 SEE ALSO
  89. L<Socket>, L<IO::Socket>
  90. =head1 AUTHOR
  91. Graham Barr. Currently maintained by the Perl Porters. Please report all
  92. bugs to <[email protected]>.
  93. =head1 COPYRIGHT
  94. Copyright (c) 1996-8 Graham Barr <[email protected]>. All rights reserved.
  95. This program is free software; you can redistribute it and/or
  96. modify it under the same terms as Perl itself.
  97. =cut