Monthly Target: $400 Donations: $602
 150% 

[INC] HTTP


Post New Thread Reply   
 
Thread Tools Display Modes
Bugsy
AMX Mod X Moderator
Join Date: Feb 2005
Location: NJ, USA
Old 10-08-2011 , 12:41   Re: [INC] HTTP
Reply With Quote #21

I am nearly finished with a new sockets module that is both non-blocking and asynchronous, I will probably re-write all of my plugins that use sockets, and this include, once its complete. But yes, a lower value would be more appropriate in socket_change() since these are blocking sockets and we want an immediate response. I didn't use the default of 100000 by-design, it was just overlooked. Using a timeout of 0 (not null) will make select return immediately so I will try that, if it gives any problems I will use 1. Thanks again buddy.

The function used for socket_change() within the module is select()
http://linux.die.net/man/2/select
Code:
timeout is an upper bound on the amount of time elapsed before select() returns.
 It may be zero, causing select() to return immediately. (This is useful for polling.) 
If timeout is NULL (no timeout), select() can block indefinitely.
__________________

Last edited by Bugsy; 10-08-2011 at 13:51.
Bugsy is offline
drekes
Veteran Member
Join Date: Jul 2009
Location: Vault 11
Old 10-29-2011 , 10:22   Re: [INC] HTTP
Reply With Quote #22

Is it possible to get the size of the file before downloading it ?
__________________

Quote:
Originally Posted by nikhilgupta345 View Post
You're retarded.
drekes is offline
Send a message via MSN to drekes
Bugsy
AMX Mod X Moderator
Join Date: Feb 2005
Location: NJ, USA
Old 10-29-2011 , 10:31   Re: [INC] HTTP
Reply With Quote #23

It was my original intention to use bytes-received==file-size for determining when a file transfer finished but, IIRC, the server doesn't always include the size of file in the HTTP header. What I did notice is the server closes the connection after sending the file so I used that to know when file transfer is complete. If you want, find a packet sniffer or if you use Firefox you can install an add-on (or maybe by default) to view headers. If you see something showing file size or w/e I can add something to retrieve size.
__________________

Last edited by Bugsy; 10-29-2011 at 10:43.
Bugsy is offline
drekes
Veteran Member
Join Date: Jul 2009
Location: Vault 11
Old 10-29-2011 , 10:47   Re: [INC] HTTP
Reply With Quote #24

Would it be bad to download multiple file & check their size with file_size ?

I'm trying to make a plugin that will check for updates for plugins listed in a file.
My idea was to check the size between the one in the plugins folder & the one from the get_plugin links here on Alliedmods & download the newer version if the file size differs.
__________________

Quote:
Originally Posted by nikhilgupta345 View Post
You're retarded.
drekes is offline
Send a message via MSN to drekes
Bugsy
AMX Mod X Moderator
Join Date: Feb 2005
Location: NJ, USA
Old 10-29-2011 , 11:41   Re: [INC] HTTP
Reply With Quote #25

You could do that but it isn't the most elegant way. I have added file-size to the include, I will post shortly.
__________________
Bugsy is offline
drekes
Veteran Member
Join Date: Jul 2009
Location: Vault 11
Old 10-29-2011 , 12:06   Re: [INC] HTTP
Reply With Quote #26

Awesome
__________________

Quote:
Originally Posted by nikhilgupta345 View Post
You're retarded.
drekes is offline
Send a message via MSN to drekes
Bugsy
AMX Mod X Moderator
Join Date: Feb 2005
Location: NJ, USA
Old 10-29-2011 , 12:19   Re: [INC] HTTP
Reply With Quote #27

New version is up:

v0.4
  • Changed socket_change() timeout from default of 100000 to 0 to avoid blocking.
  • Added file size to download progress forward.
  • Added FTP_AbortTransfer() function to stop a current file transfer.
  • Fixed bug where if an error occurred opening\creating the local file the download would still proceed. Reported by dummy82.

For what you're trying to do drekes, I did not want to add a function that solely retrieved file-size because it would be a lot of redundant code. What you can do instead is start a transfer and on the first forward call you can compare existing size to new size and abort transfer if same, like in the example below. I have not thoroughly tested a lot of files to see if 'Content-Size' is always included in the http header, if it's not included then file-size will just be 0 in the forward.
PHP Code:
#include <amxmodx>
#include <http>

new const Version[] = "0.1";

new 
g_CurrentSize 5242880;

public 
plugin_init()
{
    
register_plugin"HTTP Test" Version "bugsy" );
    
    
register_concmd"test" "DownloadFile" );
}

public 
DownloadFile()
{
    
HTTP_DownloadFile"http://download.thinkbroadband.com/5MB.zip" "ZIP.ZIP" );
}

public 
HTTP_Download( const szFile[] , iDownloadID iBytesRecv iFileSize bool:TransferComplete )
{
    if ( 
iFileSize == g_CurrentSize )
    {
        
server_print"No change in file size" );
        
HTTP_AbortTransferiDownloadID );
        return;
    }
    
    if ( 
TransferComplete )
    {
        
server_print"%s download complete!" szFile );
    }
    else
    {
        
server_print"File=[%s] DownloadID=%d BytesTransferred=%d Size=%d" szFile iDownloadID iBytesRecv iFileSize );
    }

__________________

Last edited by Bugsy; 10-29-2011 at 12:21.
Bugsy is offline
drekes
Veteran Member
Join Date: Jul 2009
Location: Vault 11
Old 10-29-2011 , 12:29   Re: [INC] HTTP
Reply With Quote #28

Perfect, thanks a lot.
__________________

Quote:
Originally Posted by nikhilgupta345 View Post
You're retarded.
drekes is offline
Send a message via MSN to drekes
Bugsy
AMX Mod X Moderator
Join Date: Feb 2005
Location: NJ, USA
Old 10-29-2011 , 13:04   Re: [INC] HTTP
Reply With Quote #29

Just posted minor fix, I forgot to set FileSize to 0 when starting a new download. Without this, the next download in the slot would contain the filesize of the previous download in that slot if 'Content-Size' was not in the new download header.

Does this work for what you're doing drekes?
__________________

Last edited by Bugsy; 10-29-2011 at 13:51.
Bugsy is offline
drekes
Veteran Member
Join Date: Jul 2009
Location: Vault 11
Old 10-29-2011 , 13:25   Re: [INC] HTTP
Reply With Quote #30

I haven't finished the plugin yet but it should be perfect for it.
I'll post feedback once the plugin is done & i had the chance to fully test it.
__________________

Quote:
Originally Posted by nikhilgupta345 View Post
You're retarded.
drekes is offline
Send a message via MSN to drekes
Reply


Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump


All times are GMT -4. The time now is 12:03.


Powered by vBulletin®
Copyright ©2000 - 2015, vBulletin Solutions, Inc.
Theme made by Freecode