[an error occurred while processing this directive] [an error occurred while processing this directive][an error occurred while processing this directive] [an error occurred while processing this directive] [an error occurred while processing this directive] [an error occurred while processing this directive] (none) [an error occurred while processing this directive] [an error occurred while processing this directive] [an error occurred while processing this directive] [an error occurred while processing this directive] [an error occurred while processing this directive][an error occurred while processing this directive] [an error occurred while processing this directive][an error occurred while processing this directive] [an error occurred while processing this directive][an error occurred while processing this directive] [an error occurred while processing this directive] [an error occurred while processing this directive] [an error occurred while processing this directive] (none) [an error occurred while processing this directive] [an error occurred while processing this directive] [an error occurred while processing this directive][an error occurred while processing this directive]
 
[an error occurred while processing this directive] [an error occurred while processing this directive]
Skåne Sjælland Linux User Group - http://www.sslug.dk Home   Subscribe   Mail Archive   Forum   Calendar   Search
MhonArc Date: [Date Prev] [Date Index] [Date Next]   Thread: [Date Prev] [Thread Index] [Date Next]   MhonArc
 

sockets som C++-streams



Hej SSLUG

Jeg har begået et bibliotek der giver understøttelse af sockets direkte
fra C++!

Bruger du sockets og C++ eller har intresse for STL C++ vil jeg meget
gerne høre fra dig!
mailto:sslug@sslug

Biblioteket samt kildetekst er at hente på min hjemmeside
http://home12.inet.tele.dk/ngr
/pub
/ngr_sockstream_11_61_tar.gz
(eller højere for seneste version)

FEATURES:
    - beskyttet af GPL
    - honorerer ISO/IEC 14882:1998(E) (se dog nedenfor)
    - kompatibel med g++-2 (med respekt for ovenstående)
    - understøtter socket_traits<PF_INET, SOCK_STREAM, IPPROTO_TCP>
    - understøtter socket_traits<PF_INET, SOCK_STREAM, IPPROTO_IP>
(jamen var det ikke det jeg sagde?)
    - udviklet på Linux.

MISFEATURES:
    - ingen dokumentation
    - mangelfuld teststrategi
    - ikke optimeret implementation
    - kun ikke-bufferede bufferere understøttes/er implemeteret
    - kun een type sockets understøttet
    - destructor kalder virtuel function
    - også udviklet vha. djgpp.

Jeg vil vedblive at udvikle på dette bibliotek men vil blive glad for
forslag, ideer og opmuntring!
(I øvrigt tak til Bjarne Stroustrup for samme)

Eksemplet viser hvordan man på "blot 6 linier" kan lave en internet
server der udskriver hvad den modtager.

Nils Åke Ljunggren


// sample -*- C++ -*- server echoing a message recieved from an/thee
internet/Internet
#include <inet.h>
#include <stdexcept>

// main program entry point:
//

int main()
{
  const uint16_t use_port= 5029;
  const uint32_t accept_connections_from= htonl(inet::any);
  const int accept_queue_size= 0;

  typedef
    socket_traits<inet::protocol_format, inet::stream,
inet::default_protocol>
    socktraits;
  typedef
    socktraits::sockaddr_type sockaddr_type;
  typedef
    basic_socketbuf
    <socktraits::protocol_format, socktraits::connection_style,
    socktraits::protocol, char> buffer_type;

  sockaddr_type
    serveraddr= { socktraits::address_format, use_port,
    { accept_connections_from } };
  buffer_type serverbuf(socktraits::make_socket());
  buffer_type clientbuf;
  istream clientstream(&clientbuf);  // use g++-2 streams for now

  try {
    if (!serverbuf.bind(&serveraddr))
      throw runtime_error("bind error");
    if (!serverbuf.listen(accept_queue_size))
      throw runtime_error("listen error");
    if
(!serverbuf.accept(dynamic_cast<buffer_type*>(clientstream.rdbuf()),
     0, 0))
      throw runtime_error("accept_error");

    for (char ch; clientstream.get(ch); cout << ch);
    cout << endl;
  }
  catch (runtime_error& e) {
    cerr << e.what() << endl;
    return 1;
  }
  catch (...) {
    cerr << "unexpected exception caught\n";
    return 2;
  }
  return 0;
}




 
Home   Subscribe   Mail Archive   Index   Calendar   Search

 
 
Questions about the web-pages to <www_admin>. Last modified 2005-08-10, 20:07 CEST [an error occurred while processing this directive]
This page is maintained by [an error occurred while processing this directive]MHonArc [an error occurred while processing this directive] # [an error occurred while processing this directive] *