Permalink
Browse files

comet stuff

git-svn-id: http://evserver.googlecode.com/svn/trunk@55 e9bb6d7e-af12-11dd-bad7-87afd3b02348
  • Loading branch information...
1 parent b3d42cd commit b235f315651fae63f8b0e84c5f81064905b16624 majek04 committed Dec 7, 2008
View
@@ -86,6 +86,10 @@ def iterator():
yield t.write("event2")
yield environ['x-wsgiorg.fdevent.readable'](fd, 1.0)
yield t.write('padding4')
+ yield environ['x-wsgiorg.fdevent.readable'](fd, 1.0)
+ yield t.write('padding4')
+ yield environ['x-wsgiorg.fdevent.readable'](fd, 1.0)
+ yield t.write('padding5')
except GeneratorExit:
pass
os.close(fd)
@@ -100,6 +104,9 @@ def GET(self):
for k, v in t.get_headers():
web.header(k, v)
+ if eid > 13:
+ raise Exception
+
def iterator():
fname = '/tmp/fifo'
try:
@@ -141,6 +148,16 @@ def iterator():
if eid == 9:
yield environ['x-wsgiorg.fdevent.readable'](fd, 1.0)
yield t.write('padding4')
+ if eid == 10:
+ yield environ['x-wsgiorg.fdevent.readable'](fd, 1.0)
+ yield t.write('padding4')
+ if eid == 11:
+ yield environ['x-wsgiorg.fdevent.readable'](fd, 1.0)
+ yield t.write('padding5')
+ if eid == 12:
+ pass
+ if eid == 13:
+ yield environ['x-wsgiorg.fdevent.readable'](fd)
except GeneratorExit:
pass
os.close(fd)
@@ -27,7 +27,7 @@ comet_keepalive_timeout = 76*1000; // 66 seconds with no data
- function that is going to destroy current conenction
for garbage collecting
*/
-safari = 0;
+
/* xhr stream, for firefox and safari */
function schedule_connection_xhr(url, callback, server_reconnect) {
var boundary = '\r\n|O|\r\n';
@@ -76,16 +76,6 @@ function schedule_connection_xhr(url, callback, server_reconnect) {
xhr = null;
};
- if(safari == 1){
- /* kill loading bar on safari */
- function f(){
- xhr.abort();
- server_reconnect(false);
- }
- setTimeout(f, 500);
- safari = 2;
- }
-
return xhr_gc;
}
@@ -115,10 +105,7 @@ function schedule_connection_longpoll(url, callback, server_reconnect) {
callback( data );
}else{
- // just try again:
- if(schedule)
- schedule();
- // server_reconnect(true);
+ server_reconnect(true);
}
}
}
@@ -175,19 +162,20 @@ function schedule_connection_htmlfile(url, user_callback, server_reconnect) {
'&callback=' + fname +
"' ></iframe>";
-
// for ie 6
kill_load_bar();
function htmlfile_close() {
+ window[fname] = function(){};
+ window[fname+'_reconnect'] = function(){};
if(transferDoc){
transferDoc.body.removeChild(ifrDiv);
+ delete(trasferDoc);
+ transferDoc = null;
+ }
+ if(ifrDiv){
+ delete(ifrDiv);
+ ifrDiv = null;
}
- delete(ifrDiv);
- ifrDiv = null;
- delete(trasferDoc);
- transferDoc = null;
- window[fname] = null;
- window[fname+'_reconnect'] = null;
CollectGarbage();
}
document.attachEvent('on'+'unload', htmlfile_close);
@@ -199,7 +187,6 @@ function schedule_connection_htmlfile(url, user_callback, server_reconnect) {
function schedule_connection_iframe(url, user_callback, server_reconnect) {
var i=0; while(window['c'+i] != undefined) i += 1;
var fname = 'c' + i;
-
window[fname] = function (data){
user_callback(data);
kill_load_bar();
@@ -214,16 +201,25 @@ function schedule_connection_iframe(url, user_callback, server_reconnect) {
'&transport=iframe'+
'&callback=' + fname );
document.body.appendChild(ifr);
- kill_load_bar();
- return function () {
- if(ifr)
+ kill_load_bar();
+ var gc = function () {
+ window[fname] = function(){};
+ window[fname+'_reconnect'] = function(){};
+ if(ifr){
document.body.removeChild(ifr);
- delete(ifr);
- ifr=null;
- window[fname] = null;
- window[fname+'_reconnect'] = null;
+ delete(ifr);
+ ifr=null;
+ }
+ try{
+ CollectGarbage();
+ }catch(e){};
};
+ try{
+ document.attachEvent('on'+'unload', gc);
+ window.attachEvent('on'+'unload', gc);
+ }catch(e){};
+ return gc;
}
function hide_iframe(ifr) {
ifr.style.display = 'block';
@@ -239,39 +235,36 @@ function hide_iframe(ifr) {
-/* server_sent_events for opera */
+/* server_sent_events for opera
+opera 9.60 is delivering messages _TWICE_.
+to fix that we need to keep track on messages. fuck.
+If they will fix it, it's going to be a huge memory drainer.
+*/
function schedule_connection_sse(url, callback) {
var es = document.createElement('event-source');
es.setAttribute('src', url +"&transport=sse");
document.body.appendChild(es);
- var last_event = '';
+ var last_events = {};
var event_callback = function (event){
- if(last_event == event.data){
+ var k = event.data.substr(0,32);
+ if(last_events[k]){
comet_log('REPEATED EVENT: ' + event.data);
- // OPERA SUCKS!
- /*
- s = '';
- for(k in event)
- s+= ' ' + k;
-
- comet_log(s);
- */
+ delete(last_events[k]);
return;
}
if(callback){
if(event.data)
callback(decode_utf8(unescape(event.data)));
}
- last_event = event.data;
- //event.data=null;
+ last_events[k] = true;
};
es.addEventListener('payload', event_callback, false);
- return function () {
+ var gc = function () {
if(es){
es.removeEventListener('payload', event_callback, false);
document.body.removeChild(es);
@@ -281,6 +274,7 @@ function schedule_connection_sse(url, callback) {
delete(es);
es = null;
};
+ return gc;
}
@@ -311,10 +305,10 @@ function guess_transport() {
if( navigator.userAgent.indexOf('Safari')!= -1 || navigator.userAgent.indexOf('Webkit')!= -1){
safari = 1;
- return 'xhr';
+ return 'xhrstream';
}
- return 'xhr';
+ return 'xhrstream';
}
transport_global = guess_transport();
@@ -398,13 +392,14 @@ function comet_connection(url, user_callback_o, transport_local) {
}
garbage_function = connect_function(get_url(url), callback, server_reconnect);
- return function (){
+ var xx = function (){
clearTimeout(keepalive_timer);
if(garbage_function)
garbage_function();
if(comet_log)
comet_log('comet: cleaning connection');
}
+ return xx;
}
@@ -44,6 +44,17 @@ function create_xhr() {
throw new Error('Could not find XMLHttpRequest or an alternative.');
}
+function post_ajax(url, data){
+ var xhr = create_xhr();
+ xhr.open('POST', url, true);
+ xhr.setRequestHeader("Content-type", "application/x-www-form-urlencoded");
+ xhr.setRequestHeader("Content-length", data.length);
+ xhr.setRequestHeader("Connection", "close");
+ xhr.send(data);
+ return(xhr);
+}
+
+
load_kill_ifr = null;
function kill_load_bar() {
if (load_kill_ifr == null) {
Oops, something went wrong.

0 comments on commit b235f31

Please sign in to comment.