Who's Online |
17 user(s) are online ( 10 user(s) are browsing Forums)
Members: 0
Guests: 17
more...
|
|
|
|
Re: sockets suck...
|
Posted on: 2011/4/5 22:24
#1341
|
Just can't stay away 
|
@TSK Quote: I don't know if it matters but you call sockread(); in two different places in your two examples. Yup, that's pretty much the whole point of the excercise...  Quote: Where do you set qt_socketSignalMask ? Is it correct ? I'm pretty much a 110% that it is correct (if not else then because it actually works in a)the other case and b) when I send a signal with Ranger).
|
|
|
|
Re: sockets suck...
|
Posted on: 2011/4/5 16:49
#1342
|
Just can't stay away 
|
@chris
Yes, it is, and that's the point! setsockopt() is supposed to make it send a signal once data arrives at the socket, and surely if I remove the IExec->Wait() line, I can see that data _has_ arrived at the socket, but the signal never comes. And that is only the second example, in the first one the signal actually arrives, and everything works as it is supposed to...
I'm banging my head against this, please somebody help!
EDIT: Also I can manually send a signal from Ranger, which means everything works _except_ that the signal is never emitted as it is supposed to.
|
|
|
|
Re: sockets suck...
|
Posted on: 2011/4/5 15:28
#1343
|
Just can't stay away 
|
@kas1e Thanks for the note, I will write you shortly. @thread I have so far been able to write this function, that just calls up google really short, allocs a signal with setsockopt and waits for bytes to read:
void sockread()
{
int sockfd = ::socket(AF_INET, SOCK_STREAM, 0);
#define MAX_BUF 1024
extern unsigned int qt_socketSignalMask; //allocated in main code
extern int safewrite(int, char *);
int count;
char buf[MAX_BUF];
int status;
struct sockaddr_in my_addr;
memset(&my_addr, 0, sizeof(my_addr));
my_addr.sin_family = AF_INET;
my_addr.sin_port = htons(80);
struct hostent *hent = gethostbyname("www.google.com");
if (!hent)
printf ("gethostbyname failed!\n");
memcpy(&my_addr.sin_addr, hent->h_addr_list[0], hent->h_length);
status = ::connect(sockfd, (struct sockaddr *)&my_addr, sizeof(my_addr));
if (status == -1)
{
perror("Connection error");
printf("errno = %d\n", errno);
exit(1);
}
printf("Connected\n");
ULONG temp = FD_ACCEPT | FD_CONNECT | FD_READ | FD_WRITE | FD_ERROR;
status = setsockopt(sockfd, SOL_SOCKET, SO_EVENTMASK, &temp, sizeof(temp));
qDebug() << "setsockopt returned " << status;
status = safewrite(sockfd, "GET www.google.com HTTP/1.0\nAccept: */*\r\n\r\n");
qDebug() << "written " << status << "bytes to socket";
printf("waiting for signal 0x%x\n", qt_socketSignalMask);
unsigned int signal = IExec->Wait(qt_socketSignalMask);
if (signal & qt_socketSignalMask)
printf("Got a SOCKET signal!\n");
count = ::read(sockfd, buf, MAX_BUF);
printf("read %d bytes from socket %d\n", count, sockfd);
::close(sockfd);
}
Now, the problem arises once I try to call this code from various places within qt. At one point, I get this very strange behavior: WORKS:
int QAbstractSocket::qt_metacall(QMetaObject::Call _c, int _id, void **_a)
{
// .... bla bla ....
if (_c == QMetaObject::InvokeMetaMethod) {
sockread();
switch (_id) {
case 0: hostFound(); break;
case 1:
// .... bla bla ....
case 12:
// ... bla bla ...
default: ;
}
_id -= 16;
}
return _id;
}
DOESN'T WORK(HANGS at IExec->Wait()):
int QAbstractSocket::qt_metacall(QMetaObject::Call _c, int _id, void **_a)
{
// .... bla bla ....
if (_c == QMetaObject::InvokeMetaMethod) {
switch (_id) {
case 0: hostFound(); break;
case 1:
// .... bla bla ....
case 12: sockread(); break;
// ... bla bla ...
default: ;
}
_id -= 16;
}
return _id;
}
What could possibly be the catch here?? I have a stack of 10MB, so it is not a stack issue... Help!
|
|
|
|
Re: sockets suck...
|
Posted on: 2011/4/2 19:54
#1344
|
Just can't stay away 
|
@LiveForIt:
Also apparently I need to connect to port 80 to use http (or smth). These are all little things that are not easy to pick up from whatever random info can be found on the web. Now i managed to connect, but calling read just blocks execution. Probably I need to use the suggestion given by Deniil to receive data.
@thread
Thanks for all the input, i will put it to the test once I get home.
|
|
|
|
sockets suck...
|
Posted on: 2011/3/31 18:44
#1345
|
Just can't stay away 
|
Does anyone have a simple, tangible example of how to properly initialize a bsdsocket and connect it to, say, " www.google.com" and download via http?? I have looked everywhere on the web, but I can only find stuff that uses ipv6 and getaddrinfo, which is useless to us... Help!
|
|
|
|
Re: serial.device problems
|
Posted on: 2011/3/30 22:03
#1346
|
Just can't stay away 
|
@xenic + Steady
Nope, that's not it, I just tried. Also note, that it doesn't crash the first time through, only the second time I try to run the program.
It must be, that because I'm using the device in shared mode it needs to only be closed once. If that's the case, it is different from os3 and it should be noted in the autodocs, which it is not.
|
|
|
|
Re: DebugPrintF
|
Posted on: 2011/3/30 21:45
#1347
|
Just can't stay away 
|
@rige+TSK
Ok, thanks a lot!
|
|
|
|
Re: DebugPrintF
|
Posted on: 2011/3/30 17:18
#1348
|
Just can't stay away 
|
Ok thanks  Is there a description of this kdebug command anywhere? I can't find anything in "SYS:Documentation/C"..?
|
|
|
|
DebugPrintF
|
Posted on: 2011/3/30 17:07
#1349
|
Just can't stay away 
|
How to turn on serial logging of this command??
My serial connection is 100% working, but when I call IExec->DebugPrintF() nothing is written to the serial. How come?
|
|
|
|
Re: serial.device problems
|
Posted on: 2011/3/27 0:35
#1350
|
Just can't stay away 
|
Apparently it is not allowed to CloseDevice twice, when access is shared. Removing on CloseDevice fixed the crash.
|
|
|
|
Re: Terminal
|
Posted on: 2011/3/26 22:47
#1352
|
Just can't stay away 
|
Thanks for the inputs  . Putty seems good, but how can I make it understand that '\n' means newline AND carriage return?? Until this is fixed, I think I will stick with Termite. EDIT: Nevermind, found the tag called "Implicit CR in every LF". Putty is good to go 
Edited by alfkil on 2011/3/26 23:09:48
|
|
|
|
Re: Terminal
|
Posted on: 2011/3/26 16:55
#1353
|
Just can't stay away 
|
@Chris I comes with windows? I can't find it there, only this online: Quote: HyperTerminal Private Edition 7.0 HyperTerminal Private Edition is a terminal emulation program. Download now Size: 3.20MB License: Shareware Price: $59.99 By: Hilgraeve, Inc I found another little neat program called termine, which does pretty much exactly what I wanted it to 
|
|
|
|
Terminal
|
Posted on: 2011/3/26 16:16
#1354
|
Just can't stay away 
|
I have just managed to get a USB to serial adapter to work on my Windoze machine, so that I can receive debug output from my sam-flex. Now the question is: What kind of terminal software do people use? I can only find trial versions of software online, and the software I'm using now ("Serial Port Monitor") reads newlines as dots (and no newline).
Help appreciated.
|
|
|
|
Re: Qt Native News
|
Posted on: 2010/12/1 18:43
#1355
|
Just can't stay away 
|
@jahc Qt is stricktly C++. And yes, it is a nice interface  . And no, the port is not done yet and probably will not be for a long time... Interlude: Qt Native News occuring between this post and the next is available at the amigans.net temporary site. Direct link to temporary site thread
Edited by Chris on 2011/4/15 18:53:27
|
|
|
|
Re: Qt Native News
|
Posted on: 2010/11/9 13:51
#1356
|
Just can't stay away 
|
@afxgroup The sqlite driver for libQtSql.so is currently working. I haven't worked on any of the other drivers. @DAX Hehe, yeah that would be great  . Currently I'm still stuck trying to get an exec signal from sockets... And then there is the whole libQtGui thing. Long way to go still. (NB: sockets are working just fine, only I'm not getting any signals from them, so when downloading data I need a QTimer object to drive the events.)
|
|
|
|
Re: bsdsocket and exec signals
|
Posted on: 2010/11/8 16:36
#1357
|
Just can't stay away 
|
EDITED: Maybe someone can help me with this one also: I'm not sure how to query the connection for data. Code hangs on both read() and IExec->Wait(): Quote: #include <sys/types.h> #include <sys/socket.h> #include <netinet/in.h> #include <arpa/inet.h> #include <string.h> #include <stdio.h> #include <stdlib.h> #include <unistd.h>
#include <netdb.h>
#include <proto/exec.h> #include <proto/bsdsocket.h>
#define MAX_BUF 100
int main(int argc, char* argv[]) { int sockd; int count; struct sockaddr_in serv_name; char buf[MAX_BUF]; int status;
/* create a socket */ sockd = socket(AF_INET, SOCK_DGRAM, 0); if (sockd == -1) { perror("Socket creation"); exit(1); }
/* server address */ serv_name.sin_family = AF_INET; struct hostent *hent = gethostbyname("www.google.com"); if (!hent) { perror ("gethostbyname failed"); exit(-1); } if (hent->h_addrtype != AF_INET) { perror("Unknown address type"); exit(-1); }
printf("hostname = %s\n", hent->h_name);
//What is supposed to happen here??? //serv_name.sin_addr.s_addr = inet_addr(hent->h_addr_list[0]); memcpy (&(serv_name.sin_addr.s_addr), hent->h_addr, hent->h_length); serv_name.sin_port = htons (12345);
/* connect to the server */ status = connect(sockd, (struct sockaddr*)&serv_name, sizeof(serv_name)); if (status == -1) { perror("Connection error"); exit(1); } printf("connected to server\n");
BYTE socketSignal = IExec->AllocSignal(-1); uint32 socketSignalMask = 1 << socketSignal;
printf("socketSignalMask = 0x%x\n", socketSignalMask);
ISocket->SocketBaseTags (SBTM_SETVAL(SBTC_SIGEVENTMASK), socketSignalMask, TAG_END);
ULONG temp = FD_ACCEPT | FD_CONNECT | FD_READ | FD_WRITE | FD_ERROR; setsockopt(sockd, SOL_SOCKET, SO_EVENTMASK, &temp, sizeof(temp));
IExec->Wait (socketSignalMask|SIGBREAKF_CTRL_C); printf("signal received\n");
count = read(sockd, buf, MAX_BUF); write(1, buf, count);
close(sockd);
IExec->FreeSignal(socketSignal); return 0; }
Edited by alfkil on 2010/11/8 17:16:02
|
|
|
|
Re: bsdsocket and exec signals
|
Posted on: 2010/11/8 15:27
#1358
|
Just can't stay away 
|
@tboeckel Ahh... Me dumbass, you smart 
|
|
|
|
Re: bsdsocket and exec signals
|
Posted on: 2010/11/8 15:08
#1359
|
Just can't stay away 
|
@tboeckel Thanks for the info! Still, I don't quite understand how it is supposed to work: The "getsockopt()" entry in the docs don't mention anything about SO_EVENTMASK as mentioned in the GetSocketEvents() entry, which makes me a little confused. Could you give an example, maybe?? EDIT: I tried inserting the following line, but it changes nothing: Quote: setsockopt(sockets[0], SOL_SOCKET, SO_EVENTMASK, (const void *)&socketSignalMask, sizeof(socketSignalMask));
|
|
|
|
bsdsocket and exec signals [NEW PROBLEM]
|
Posted on: 2010/11/8 14:15
#1360
|
Just can't stay away 
|
Argh!... I need to be able to do asynchronous io with sockets using exec signals, but I can't get it to work. The ISocket->SocketBaseTags() should set up bsdlibrary to send exec signals, but the signal never arrives. If you remove the IExec->Wait() statement, the code works of course... Help! Quote: #define DATA1 "test string 1" #define DATA2 "test string 2"
#include <sys/types.h> #include <sys/socket.h> #include <stdio.h> #include <errno.h> #include <fcntl.h>
#include <proto/exec.h> #include <proto/bsdsocket.h>
/* * set_nonblocking(): Set a fd into nonblocking mode. */ static int set_nonblocking(int fd) { int val;
if((val = fcntl(fd, F_GETFL, 0)) == -1) return -1; if (!(val & O_NONBLOCK)) { val |= O_NONBLOCK; fcntl(fd, F_SETFL, val); } return 0; }
/* * set_blocking(): Set a fd into blocking mode. */ static int set_blocking(int fd) { int val;
if((val = fcntl(fd, F_GETFL, 0)) == -1) return -1; if (val & O_NONBLOCK) { val &= ~O_NONBLOCK; fcntl(fd, F_SETFL, val); } return 0; }
/* * __socketpair_tcp(): Create a socket pipe. */ int __socketpair_tcp(int fd[2]) { int listener; struct sockaddr sock; socklen_t socklen = sizeof(sock); int len = socklen; int one = 1; int connect_done = 0;
fd[0] = fd[1] = listener = -1;
memset(&sock, 0, sizeof(sock));
if ((listener = socket(PF_INET, SOCK_STREAM, 0)) == -1) { goto failed; }
setsockopt(listener, SOL_SOCKET, SO_REUSEADDR, (char *)&one, sizeof(one));
if (listen(listener, 1) != 0) { goto failed; }
if (getsockname(listener, &sock, (socklen_t *) &socklen) != 0) { goto failed; }
if ((fd[1] = socket(PF_INET, SOCK_STREAM, 0)) == -1) { goto failed; }
setsockopt(fd[1], SOL_SOCKET, SO_REUSEADDR, (char *)&one, sizeof(one));
set_nonblocking(fd[1]);
if (connect(fd[1], (struct sockaddr *) &sock, sizeof(sock)) == -1) { if (errno != EINPROGRESS) { goto failed; } connect_done = 1; } else { connect_done = 1; }
if ((fd[0] = accept(listener, &sock, (socklen_t *) &len)) == -1) { goto failed; }
setsockopt(fd[0], SOL_SOCKET, SO_REUSEADDR, (char *) &one, sizeof(one));
close(listener); listener = -1; if (connect_done == 0) { if (connect(fd[1], (struct sockaddr *) &sock, sizeof(sock)) != 0) { goto failed; } }
set_blocking(fd[1]);
/* all OK! */ return 0;
failed: printf("socketpair failed!\n"); if (fd[0] != -1) close(fd[0]); if (fd[1] != -1) close(fd[1]); if (listener != -1) close(listener); return -1; }
main() { int sockets[2], child; char buf[1024];
/* Get the socket pair */ if (__socketpair_tcp(sockets) < 0) { printf("error %d on socketpair\n", errno); exit(1); } BYTE socketSignal = IExec->AllocSignal(-1); uint32 socketSignalMask = 1 << socketSignal;
printf("socketSignalMask = 0x%x\n", socketSignalMask);
ISocket->SocketBaseTags (SBTM_SETVAL(SBTC_SIGEVENTMASK), socketSignalMask, TAG_END);
/* write message to child */ if (write(sockets[1], DATA1, sizeof(DATA1)) < 0) { printf("error %d writing socket\n", errno); exit(1); }
/* send message to parent */ if (write(sockets[0], DATA2, sizeof(DATA1)) < 0) { printf("error %d writing socket\n", errno); exit(1); }
IExec->Wait(socketSignalMask);
/* get message from parent */ if (read(sockets[0], buf, sizeof(buf)) < 0) { printf("error %d reading socket\n", errno); exit(1); } printf("-->%s\n", buf);
IExec->FreeSignal (socketSignal);
/* finished */ close(sockets[0]); close(sockets[1]); }
(Note, that this is a test scenario, so don't get too hung up on the code actually making any practical sense. It is just the same thread reading and writing to/from the same socket pair.)
Edited by alfkil on 2010/11/8 18:55:39
|
|
|
|