Skip to content

feat: add timeout option #4

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
25 changes: 17 additions & 8 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
Overview
--------
## Overview

This is a simple MQL4 wrapper that uses Windows native wininet.dll and
shell32.dll libraries and is supported by MT4 build 600 or newer.
@@ -11,8 +10,7 @@ Following features are currently supported:

- open HTTP(S) URI in default system's web browser

How to use
----------
## How to use

`mql4-http` is using system's dll libraries so make sure you enable DLL imports in
MT4 before running it (Tools -> Options -> Expert Advisors -> Allow DLL imports)
@@ -30,6 +28,19 @@ int start () {
}
```

In order to set timeout, use second argument (only "`n`s" format is supported):

```c
#include <mql4-http.mqh>

int start () {

httpGET("http://example.com/long-running-task.php", "60s");

return(0);
}
```

```c
#include <mql4-http.mqh>

@@ -43,17 +54,15 @@ int start () {

You can also [watch this video demonstration](http://screencast.com/t/UVMAlgCjJ2)

Credits
-------
## Credits

This library was based on following great resources:

- HTTP Wininet sample: http://codebase.mql4.com/8115

- EasyXML parser: http://www.mql5.com/code/1998

License
-------
## License

This is free and unencumbered software released into the public domain.

19 changes: 18 additions & 1 deletion src/mql4-http.mqh
Original file line number Diff line number Diff line change
@@ -30,6 +30,12 @@ int InternetOpenW(
string sProxyBypass="",
int lFlags=0
);
int InternetSetOptionW(
int hInternet,
int dwOption,
int & lpBuffer[],
int dwBufferLength
);
int InternetOpenUrlW(
int hInternetSession,
string sUrl,
@@ -52,6 +58,7 @@ int InternetCloseHandle(
#define INTERNET_FLAG_RELOAD 0x80000000
#define INTERNET_FLAG_NO_CACHE_WRITE 0x04000000
#define INTERNET_FLAG_PRAGMA_NOCACHE 0x00000100
#define INTERNET_OPTION_CONNECT_TIMEOUT 2

int hSession_IEType;
int hSession_Direct;
@@ -82,9 +89,19 @@ int hSession(bool Direct)
}
}

string httpGET(string strUrl)
string httpGET(string strUrl, string timeoutInSeconds = "")
{
int handler = hSession(false);
if (timeoutInSeconds != "")
{
int timeout=StrToInteger(timeoutInSeconds) * 1000;
int option[] = {0};
option[0] = timeout;
InternetSetOptionW(handler,
INTERNET_OPTION_CONNECT_TIMEOUT,
option, 4);
}

int response = InternetOpenUrlW(handler, strUrl, NULL, 0,
INTERNET_FLAG_NO_CACHE_WRITE |
INTERNET_FLAG_PRAGMA_NOCACHE |