-
-
Notifications
You must be signed in to change notification settings - Fork 135
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
First bits to create an asynchronous nodejs alerts loop.
- Loading branch information
Showing
6 changed files
with
88 additions
and
2 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
var lt = require('../../../swig/build/Release/jlibtorrent'); | ||
|
||
var alert_mask = lt.alert.all_categories; | ||
var sp = new lt.settings_pack(); | ||
|
||
sp.set_int(lt.settings_pack.alert_mask, alert_mask); | ||
|
||
var s = new lt.session(sp); | ||
|
||
lt.session_alerts_loop(s); | ||
|
||
process.stdout.write('Press ENTER to exit...'); | ||
process.stdin.once('data', function (data) { | ||
process.exit(0); | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -397,3 +397,36 @@ boost::shared_ptr<peer_plugin> swig_torrent_plugin::new_connection(libtorrent::p | |
swig_peer_plugin* swig_torrent_plugin::new_peer_connection(libtorrent::peer_connection_handle const& pc) { | ||
return NULL; | ||
} | ||
|
||
This comment has been minimized.
Sorry, something went wrong.
This comment has been minimized.
Sorry, something went wrong.
gubatron
Collaborator
|
||
#ifdef LIBTORRENT_SWIG_NODE | ||
|
||
#include <uv.h> | ||
|
||
void session_alerts_loop_fn(void *arg) { | ||
libtorrent::session& s = *((libtorrent::session*) arg); | ||
|
||
libtorrent::time_duration max_wait = std::chrono::milliseconds(500); | ||
|
||
std::vector<alert*> v; | ||
while (true) { | ||
alert* ptr = s.wait_for_alert(max_wait); | ||
|
||
if (ptr != NULL) { | ||
s.pop_alerts(&v); | ||
printf("alerts (%d)\n", v.size()); | ||
long size = v.size(); | ||
for (int i = 0; i < size; i++) { | ||
alert* a = v[i]; | ||
printf("%d - %s - %s\n", a->type(), a->what(), a->message().c_str()); | ||
} | ||
} | ||
} | ||
} | ||
|
||
void session_alerts_loop(libtorrent::session& s) { | ||
|
||
uv_thread_t t; | ||
uv_thread_create(&t, session_alerts_loop_fn, &s); | ||
} | ||
|
||
#endif |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
is it ok to add this directly on swig/libtorrent.h?
or is it better to add it from the libtorrent.i (swig) file.
... although I guess the LIBTORRENT_SWIG_NODE compilation flag check would save this code from going to java land.