Commits

Michael Granger committed 0d45770

Actually adding examples

  • Participants
  • Parent commits 8d69116

Comments (0)

Files changed (1)

    - etc.
  * Cleanly abandon terminated operations where supported
  * Memory-handling cleanup to avoid leaks, corruption, and other
+diff --git a/examples/asynchronous_api.rb b/examples/asynchronous_api.rb
+new file mode 100644
+--- /dev/null
++++ b/examples/asynchronous_api.rb
+@@ -0,0 +1,53 @@
++#!/usr/bin/env ruby
++
++require 'openldap'
++
++SERVER = 'ldap://ldap.laika.com/'
++BASE   = 'dc=laika,dc=com'
++
++t = Thread.new do
++	Thread.current.abort_on_exception = true
++
++	# Create a new connection
++	c = OpenLDAP::Connection.new( SERVER )
++
++	# Set some options
++	c.deref_aliases = true
++	c.timeout       = 10
++	c.sizelimit     = 200
++
++	# Connect to the server and wrap the connection in a TLS channel
++	c.start_tls
++
++	# Search (synchronously) in a Thread and return the results when done.
++	c.search( BASE, 
++		scope: :subtree, 
++		filter: '(objectClass=inetOrgPerson)',
++		attributes: [ '*', '+' ],
++		deref_aliases: :always,
++		sizelimit: 10,
++		timeout: 10,
++		attrs_only: false,
++	  )
++end
++
++# Set up another thread that will output stuff while the LDAP stuff runs to demonstrate that it
++# doesn't block other threads (under 1.9, anyway).
++t2 = Thread.new do
++	Thread.current.abort_on_exception = true
++	Thread.current[ :done ] = false
++
++	puts "Thread 2 waiting..."
++	until Thread.current[ :done ]
++		print "."
++		sleep 1
++	end
++	puts "thread 2 done."
++end
++
++
++puts t1.join
++t2[ :done ] = true
++t2.join
++
++
+diff --git a/examples/synchronous_api.rb b/examples/synchronous_api.rb
+new file mode 100644
+--- /dev/null
++++ b/examples/synchronous_api.rb
+@@ -0,0 +1,53 @@
++#!/usr/bin/env ruby
++
++require 'openldap'
++
++SERVER = 'ldap://ldap.laika.com/'
++BASE   = 'dc=laika,dc=com'
++
++t = Thread.new do
++	Thread.current.abort_on_exception = true
++
++	# Create a new connection
++	c = OpenLDAP::Connection.new( SERVER )
++
++	# Set some options
++	c.deref_aliases = true
++	c.timeout       = 10
++	c.sizelimit     = 200
++
++	# Connect to the server and wrap the connection in a TLS channel
++	c.start_tls
++
++	# Search (synchronously) in a Thread and return the results when done.
++	c.search( BASE, 
++		scope: :subtree, 
++		filter: '(objectClass=inetOrgPerson)',
++		attributes: [ '*', '+' ],
++		deref_aliases: :always,
++		sizelimit: 10,
++		timeout: 10,
++		attrs_only: false,
++	  )
++end
++
++# Set up another thread that will output stuff while the LDAP stuff runs to demonstrate that it
++# doesn't block other threads (under 1.9, anyway).
++t2 = Thread.new do
++	Thread.current.abort_on_exception = true
++	Thread.current[ :done ] = false
++
++	puts "Thread 2 waiting..."
++	until Thread.current[ :done ]
++		print "."
++		sleep 1
++	end
++	puts "thread 2 done."
++end
++
++
++puts t1.join
++t2[ :done ] = true
++t2.join
++
++
 diff --git a/ext/connection.c b/ext/connection.c
 --- a/ext/connection.c
 +++ b/ext/connection.c